import MySQLdb
db=MySQLdb.connect("ip","数据库用户名","密码","库名", charset='utf8')
cur=db.cursor()
all=cur.execute("select * from 表")
t=cur.fetchone()
print(t)
print(all)
前提是:
1、需要安装mysql库,python3以下版本的用 pip install PyMySQL,python以上版本的用pip install MySqlcliect。