Pure Python MySQL Driver
Project Links
Meta
Author: Inada Naoki, Yutaka Matsubara
Requires Python: >=3.7
Classifiers
Development Status
- 5 - Production/Stable
Programming Language
- Python :: 3
- Python :: 3.7
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Topic
- Database
PyMySQL
This package contains a pure-Python MySQL client library, based on PEP 249.
Requirements
- Python -- one of the following:
- MySQL Server -- one of the following:
Installation
Package is uploaded on PyPI.
You can install it with pip:
$ python3 -m pip install PyMySQL
To use "sha256_password" or "caching_sha2_password" for authenticate, you need to install additional dependency:
$ python3 -m pip install PyMySQL[rsa]
To use MariaDB's "ed25519" authentication method, you need to install additional dependency:
$ python3 -m pip install PyMySQL[ed25519]
Documentation
Documentation is available online: https://pymysql.readthedocs.io/
For support, please refer to the StackOverflow.
Example
The following examples make use of a simple table
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) COLLATE utf8_bin NOT NULL,
`password` varchar(255) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
AUTO_INCREMENT=1 ;
import pymysql.cursors
# Connect to the database
connection = pymysql.connect(host='localhost',
user='user',
password='passwd',
database='db',
cursorclass=pymysql.cursors.DictCursor)
with connection:
with connection.cursor() as cursor:
# Create a new record
sql = "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()
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
cursor.execute(sql, ('webmaster@python.org',))
result = cursor.fetchone()
print(result)
This example will print:
{'password': 'very-secret', 'id': 1}
Resources
- DB-API 2.0: https://www.python.org/dev/peps/pep-0249/
- MySQL Reference Manuals: https://dev.mysql.com/doc/
- MySQL client/server protocol: https://dev.mysql.com/doc/internals/en/client-server-protocol.html
- "Connector" channel in MySQL Community Slack: https://lefred.be/mysql-community-on-slack/
- PyMySQL mailing list: https://groups.google.com/forum/#!forum/pymysql-users
License
PyMySQL is released under the MIT License. See LICENSE for more information.
May 21, 2024
1.1.1
Jun 26, 2023
1.1.0
Jun 15, 2023
1.1.0rc2
May 25, 2023
1.1.0rc1
Mar 28, 2023
1.0.3
Mar 24, 2023
1.0.3rc1
Jan 09, 2021
1.0.2
Jan 08, 2021
1.0.1
Jan 07, 2021
1.0.0
Sep 10, 2020
0.10.1
Jul 18, 2020
0.10.0
Dec 18, 2018
0.9.3
Jul 04, 2018
0.9.2
Jul 02, 2018
0.9.1
Jun 27, 2018
0.9.0
May 07, 2018
0.8.1
Dec 20, 2017
0.8.0
Apr 05, 2017
0.7.11
Feb 14, 2017
0.7.10
Sep 03, 2016
0.7.9
Sep 01, 2016
0.7.8
Aug 29, 2016
0.7.7
Jul 29, 2016
0.7.6
Jun 28, 2016
0.7.5
May 26, 2016
0.7.4
May 19, 2016
0.7.3
Feb 24, 2016
0.7.2
Jan 14, 2016
0.7.1
Jan 10, 2016
0.7.0
Sep 30, 2015
0.6.7
Feb 28, 2015
0.6.6
Feb 25, 2015
0.6.4
Feb 25, 2015
0.6.4.dev1
Dec 02, 2014
0.6.3
Apr 21, 2014
0.6.2
Oct 11, 2013
0.6.1
Oct 04, 2013
0.6
Nov 08, 2011
0.5
Dec 27, 2010
0.4
Dec 14, 2010
0.3
Jun 16, 2009
0.0rc0