下面讲讲关于python_pymysql基本操作,文字的奥妙在于贴近主题相关。所以,闲话就不谈了,我们直接看下文吧,相信看完python_pymysql基本操作这篇文章你一定会有所受益。
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='root',
password='password',
db='mysql_test',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
try:
with connection.cursor() as cursor:
# Create a new record
sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
cursor.execute(sql, ('test@python.org', 'test123!'))
# connection is not autocommit by default. So you must commit to save
# your changes.
connection.commit()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `email`,`password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('test@python.org',))
result = cursor.fetchone()
print(result)
finally:
connection.close()
https://pypi.org/project/PyMySQL/#documentation
对于以上python_pymysql基本操作相关内容,大家还有什么不明白的地方吗?或者想要了解更多相关,可以继续关注我们的行业资讯板块。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。