时间:2021-07-01 10:21:17 帮助过:25人阅读
import pymysql
#获取连接
try:
conn=pymysql.connect(
host=‘127.0.0.1‘,
user=‘root‘,
password=‘123456‘,
db=‘news‘,
port=3306,
charset=‘utf8‘
)
#获取数据
cursor=conn.cursor()
cursor.execute(‘SELECT * FROM news ORDER BY id DESC;‘)
rest=cursor.fetchone()
print(rest)
#关闭连接
conn.close()
except pymysql.Error as e:
print(‘Error:%s‘%e)
python连接mysql数据库
标签:获取数据 print 数据 connect error 数据库 .exe cep fetch