python连接MySQL数据库实例分析
更新时间:2015年05月12日 12:25:49 作者:vivi
这篇文章主要介绍了python连接MySQL数据库,实例分析了Python操作MySQL的相关技巧,需要的朋友可以参考下
本文实例讲述了python连接MySQL数据库的方法。分享给大家供大家参考。具体实现方法如下:
import MySQLdb
conn = MySQLdb.connect(host="localhost",
user="root",
passwd="123456",
db="test")
cursor = conn.cursor()
cursor.execute("select * from hard")
res = cursor.fetchall()
for x in res:
print x
cursor.close()
conn.close()
运行结果如下:

希望本文所述对大家的python程序设计有所帮助。
相关文章
Python 的 __str__ 和 __repr__ 方法对比
这篇文章主要介绍了Python 的 __str__ 和 __repr__ 方法的相关资料,帮助大家区分__str__ 和 __repr__ ,感兴趣的朋友可以了解下2020-09-09


最新评论