一:安装Mysql-python驱动 pip install mysql 二:连接到Mysql服务器的test数据库 #!/usr/bin/Python # -*- coding: UTF
pip install mysql
#!/usr/bin/Python
# -*- coding: UTF-8 -*-
import mysql.connector
if __name__ == "__main__":
# 打开数据库连接
conn=mysql.connector.connect(host='IP',
user='root',
passwd='1234',
db='dbName')
# 使用cursor()方法获取操作游标
cursor=conn.cursor()
# 使用execute方法执行SQL语句
cursor.execute('select * from tset where 1=1') #表查询
# 使用 fetchone() 方法获取一条数据库。
values=cursor.fetchall()
print(values)
# 关闭数据库连接
cursor.close()
--结束END--
本文标题: win7上python2.7连接mysql数据库的方法
本文链接: https://www.lsjlt.com/news/13811.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
2024-05-02
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0