当前位置 : 主页 > 编程语言 > python >

python链接mysql pymysql

来源:互联网 收集:自由互联 发布时间:2021-06-25
python链接mysql import pymysqlconn = pymysql.connect(user= ‘ user1 ‘ , password= ‘ 123456 ‘ , database= ‘ gbt2019 ‘ , charset= ‘ utf8 ‘ )cursor = conn.cursor()query = ( ‘ select id, title from data_2019100501 ‘ )cursor

python链接mysql

import pymysql

conn = pymysql.connect(user=user1, password=123456, database=gbt2019, charset=utf8)
cursor = conn.cursor()
query = (select id, title from data_2019100501)
cursor.execute(query)
for (id, title) in cursor:
    print(id, title)
cursor.close()
conn.close()
网友评论