纯python mysql驱动程序

anthill-PyMySQL的Python项目详细描述


Documentation Statushttps://badge.fury.io/py/PyMySQL.svghttps://travis-ci.org/PyMySQL/PyMySQL.svg?branch=masterhttps://coveralls.io/repos/PyMySQL/PyMySQL/badge.svg?branch=master&service=githubhttps://img.shields.io/badge/license-MIT-blue.svg

pymysql

这个包包含一个基于PEP 249的纯python mysql客户端库。

大多数公共api都与mysqlclient和mysqldb兼容。

注意:pymysql不支持低级api,mysql提供类似于data-seek的api。 存储结果,并使用结果。您应该使用PEP 249中定义的高级api。 但是,由于PEP 249不包括 他们的用例。

Requirements

  • python–以下之一:
  • MySQL服务器–以下之一:

Installation

包上载于PyPI

您可以使用pip安装它:

$ python3 -m pip install PyMySQL

要使用“SHA256密码”或“缓存SHA26密码”进行身份验证, 您需要安装其他依赖项:

$ python3 -m pip install PyMySQL[rsa]

Documentation

在线提供文档:https://pymysql.readthedocs.io/

有关支持,请参阅StackOverflow

Example

下面的示例使用一个简单的表

CREATETABLE`users`(`id`int(11)NOTNULLAUTO_INCREMENT,`email`varchar(255)COLLATEutf8_binNOTNULL,`password`varchar(255)COLLATEutf8_binNOTNULL,PRIMARYKEY(`id`))ENGINE=InnoDBDEFAULTCHARSET=utf8COLLATE=utf8_binAUTO_INCREMENT=1;
importpymysql.cursors# Connect to the databaseconnection=pymysql.connect(host='localhost',user='user',password='passwd',db='db',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)try:withconnection.cursor()ascursor:# Create a new recordsql="INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"cursor.execute(sql,('webmaster@python.org','very-secret'))# connection is not autocommit by default. So you must commit to save# your changes.connection.commit()withconnection.cursor()ascursor:# Read a single recordsql="SELECT `id`, `password` FROM `users` WHERE `email`=%s"cursor.execute(sql,('webmaster@python.org',))result=cursor.fetchone()print(result)finally:connection.close()

此示例将打印:

{'password':'very-secret','id':1}

License

pymysql是在mit许可下发布的。有关详细信息,请参见许可证。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java LineNumberReader。如果查询行为不正确,则返回readLine()   java包含了一个使用AndroidX的工具栏,这让我的应用程序崩溃了   JVM设置通过“java jar”运行应用程序的最佳实践   java如何获取ImageButton宽度   java Oracle SQLLDR实用程序无响应   列出Java获取对象的arrayList中最常见的元素   java使用带有FlowLayout的getContentpane对布局应用更改,但不起作用为什么?   在java中,我可以在画布上绘制画布吗?   编译游戏代码时发生java异常错误   从firestore获取java Webview失败   java将TableLayout中单元格的内容向右对齐   java无法在发布模式下启动活动(使用proguard安卓optimize配置)   java允许在线程期间进行GUI更新。睡觉   java如何对以变量为列表的列表进行排序   API URL上的java Google云端点异常