import pymysql
ccon=pymysql.connect(
host=‘127.0.0.1‘,
user=‘root‘,
password=‘password‘,
port=3306,
db=‘sys‘,
charset=‘utf8‘
)
cur=ccon.cursor()
sql=‘select*from sys_config ‘
cur.execute(sql)
data=cur.fetchall()
for i in data[:2]:
print(i)
cur.close()
ccon.close()
...
(‘diagnostics.allow_i_s_tables‘, ‘OFF‘, datetime.datetime(2020, 9, 7, 23, 32, 8), None)
(‘diagnostics.include_raw‘, ‘OFF‘, datetime.datetime(2020, 9, 7, 23, 32, 8), None)
#mysql 数据库中的自带sys库,查询其中表名为sys_config的前两条数据