参考:
https://blog.csdn.net/qq_39928840/article/details/81132230
https://www.cnblogs.com/xfxing/p/9322199.html
工具:pycharm
安装 pymysql:打开pycharm-点击底部“terminal”- 输入“pip install pymysql”
代码:
import pymysql
#使用pymsql模块连接数据库
conn = pymysql.connect(
user = 'root',
password = '(你的数据库密码)',
host = '(你的数据库ip)',
database = '(你的数据库名称)',
charset = '(编码格式必须要与数据库一直,一般是‘utf8’)'
)
#获取游标
cursor = conn.cursor()
#查询
sql = 'select * from TCommodityF10 '
#执行sql语句
count =cursor.execute(sql)
#获取结果
result = cursor.fetchall() #fechall一次读取全部数据
print(result)
for row in result:
print(row)
print("\n")