MySQLdb 防止并发出错

import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("localhost", "testuser", "test123", "TESTDB", charset='utf8',port = 3306)

# 使用cursor()方法获取操作游标 
cursor = db.cursor()

# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()

print "Database version : %s " % data

# 关闭数据库连接
db.close()

pip install mysqlclient

 

posted @ 2022-02-16 16:44  CodeYaSuo  阅读(38)  评论(0编辑  收藏  举报