时间:2021-07-01 10:21:17 帮助过:2人阅读
3. windows版如下:
注意事项:1.port后面写int而不是str;
2.添加charset=‘utf8‘以保证查出的中文字符能正常显示;
1 # -*- coding: utf-8 -*- 2 import pymysql 3 4 conn = pymysql.connect(host = ‘XXXXXX‘, port = 1234, user = ‘****‘ , password = ‘*****‘, db = ‘xxxx‘, charset = ‘utf8‘) 5 cur = conn.cursor() 6 cur.execute("USE xxxx") 7 8 cur.execute("SELECT * from xxxx where id = 1039") 9 print(cur.fetchone()) 10 cur.close() 11 conn.close()
python3连接mysql
标签: