mysql.connect-查询前5条记录

import mysql.connector
conn= mysql.connector.Connect(
    host=‘localhost‘,
    user=‘root‘,
    passwd=‘admin‘,
    database=‘testcode‘
)
print(‘1.‘,conn)
cmd = conn.cursor()  # 光标行
cmd=conn.cursor()
cmd.execute(‘select * from test‘)
print(‘5.‘,cmd.fetchmany(5))

相关推荐