#!/usr/lib/python3
# -*- coding: UTF-8 -*-

import pymysql

db = pymysql.connect("192.168.130.201", "root", "123456.abcd", "gaxz")
cursor = db.cursor()
cursor.execute("select version()")
data = cursor.fetchone()
print("Database version is %s add %s" % (data, "aa"))

# SQL 查询语句
sql = "SELECT * FROM statuses \
       WHERE id BETWEEN %d AND %d" % (10, 20)
print(sql)
try:
    # 执行SQL语句
    cursor.execute(sql)
    # db.commit()
    # 获取所有记录列表
    results = cursor.fetchall()
    for row in results:
        print(row)

except Exception as e:
    print(e.args)
    # db.rollback()

# 关闭数据库连接
db.close()

49f352b1d843ed983dbef1882ad8a200468213c8
<mask token>

<mask token>
cursor.execute('select version()')
<mask token>
print('Database version is %s add %s' % (data, 'aa'))
<mask token>
print(sql)
try:
    cursor.execute(sql)
    results = cursor.fetchall()
    for row in results:
        print(row)
except Exception as e:
    print(e.args)
db.close()

<mask token>
db = pymysql.connect('192.168.130.201', 'root', '123456.abcd', 'gaxz')
cursor = db.cursor()
cursor.execute('select version()')
data = cursor.fetchone()
print('Database version is %s add %s' % (data, 'aa'))
sql = 'SELECT * FROM statuses        WHERE id BETWEEN %d AND %d' % (10, 20)
print(sql)
try:
    cursor.execute(sql)
    results = cursor.fetchall()
    for row in results:
        print(row)
except Exception as e:
    print(e.args)
db.close()

import pymysql
db = pymysql.connect('192.168.130.201', 'root', '123456.abcd', 'gaxz')
cursor = db.cursor()
cursor.execute('select version()')
data = cursor.fetchone()
print('Database version is %s add %s' % (data, 'aa'))
sql = 'SELECT * FROM statuses        WHERE id BETWEEN %d AND %d' % (10, 20)
print(sql)
try:
    cursor.execute(sql)
    results = cursor.fetchall()
    for row in results:
        print(row)
except Exception as e:
    print(e.args)
db.close()

#!/usr/lib/python3
# -*- coding: UTF-8 -*-

import pymysql

db = pymysql.connect("192.168.130.201", "root", "123456.abcd", "gaxz")
cursor = db.cursor()
cursor.execute("select version()")
data = cursor.fetchone()
print("Database version is %s add %s" % (data, "aa"))

# SQL 查询语句
sql = "SELECT * FROM statuses \
       WHERE id BETWEEN %d AND %d" % (10, 20)
print(sql)
try:
    # 执行SQL语句
    cursor.execute(sql)
    # db.commit()
    # 获取所有记录列表
    results = cursor.fetchall()
    for row in results:
        print(row)

except Exception as e:
    print(e.args)
    # db.rollback()

# 关闭数据库连接
db.close()
