首页 > 代码库 > python3连接mysql

python3连接mysql

#!/usr/bin/python3

import pymysql

conn = pymysql.connect(host=10.60.10.11,port=3306,user=root,passwd=xxxxx,db=haoxx)

cur = conn.cursor()

cur.execute("select car_id,car_name from car where car_id < 5")

for i in cur.fetchall():
    print(i)

cur.close()
conn.close()

 

python3连接mysql