您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python PyMsql

bubuko 2022/1/25 18:56:31 python 字数 6678 阅读 961 来源 http://www.bubuko.com/infolist-5-1.html

PyMySQL PyMySQL是基于python连接操作mysql库的第三方库 介绍:代码托管地址:https://github.com/PyMySQL/PyMySQL 在线文档:https://pymysql.readthedocs.io/en/latest/index.html 安装 pytho ...

PyMySQL

  

    PyMySQL是基于python连接操作mysql库的第三方库

  •  介绍:代码托管地址:https://github.com/PyMySQL/PyMySQL
  •     在线文档:https://pymysql.readthedocs.io/en/latest/index.html

 

安装

   python3 -m pip install PyMySQL

 

环境要求

  • Python – one of the following:
  • MySQL Server – one of the following:

示例

可以使用分步式的写法,创建连接,创建游标,执行语句,关闭游标,关闭连接的方式,使用mysql数据库。

但是不建议这样做,建议使用关键字with使用PyMySQL操作mysql数据库:

 1 import pymysql.cursors
 2 
 3 # Connect to the database
 4 connection = pymysql.connect(host=localhost,
 5                              user=user,
 6                              password=passwd,
 7                              database=db,
 8                              charset=utf8mb4,
 9                              cursorclass=pymysql.cursors.DictCursor)
10 
11 with connection:
12     with connection.cursor() as cursor:
13         # Create a new record
14         sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
15         cursor.execute(sql, (webmaster@python.org, very-secret))
16 
17     # connection is not autocommit by default. So you must commit to save
18     # your changes.
19     connection.commit()
20 
21     with connection.cursor() as cursor:
22         # Read a single record
23         sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
24         cursor.execute(sql, (webmaster@python.org,))
25         result = cursor.fetchone()
26         print(result)

 

 

 

实战:

待补充:......

 

 

 

 参考:

https://github.com/chendemo12/knowledgegraph/wiki/pymysql%E5%AE%98%E6%96%B9%E6%96%87%E6%A1%A3

https://pymysql.readthedocs.io/en/latest/index.html

 

 

 

 

 

 




python PyMsql

原文:https://www.cnblogs.com/liveforlearn/p/15187604.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶