Pure Python MySQL Driver
Project Links
Meta
Author: Inada Naoki, Yutaka Matsubara
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
Programming Language
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Intended Audience
- Developers
Topic
- Database
PyMySQL
This package contains a pure-Python MySQL and MariaDB 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/
- Getting Help With MariaDB https://mariadb.com/kb/en/getting-help-with-mariadb/
- 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.
1.1.2
Aug 24, 2025
1.1.1
May 21, 2024
1.1.0
Jun 26, 2023
1.1.0rc2
Jun 15, 2023
1.1.0rc1
May 25, 2023
1.0.3
Mar 28, 2023
1.0.3rc1
Mar 24, 2023
1.0.2
Jan 09, 2021
1.0.1
Jan 08, 2021
1.0.0
Jan 07, 2021
0.10.1
Sep 10, 2020
0.10.0
Jul 18, 2020
0.9.3
Dec 18, 2018
0.9.2
Jul 04, 2018
0.9.1
Jul 02, 2018
0.9.0
Jun 27, 2018
0.8.1
May 07, 2018
0.8.0
Dec 20, 2017
0.7.11
Apr 05, 2017
0.7.10
Feb 14, 2017
0.7.9
Sep 03, 2016
0.7.8
Sep 01, 2016
0.7.7
Aug 29, 2016
0.7.6
Jul 29, 2016
0.7.5
Jun 28, 2016
0.7.4
May 26, 2016
0.7.3
May 19, 2016
0.7.2
Feb 24, 2016
0.7.1
Jan 14, 2016
0.7.0
Jan 10, 2016
0.6.7
Sep 30, 2015
0.6.6
Feb 28, 2015
0.6.4
Feb 25, 2015
0.6.4.dev1
Feb 25, 2015
0.6.3
Dec 02, 2014
0.6.2
Apr 21, 2014
0.6.1
Oct 11, 2013
0.6
Oct 04, 2013
0.5
Nov 08, 2011
0.4
Dec 27, 2010
0.3
Sep 03, 2010
0.2
Jun 16, 2009
0.3_1
Nov 08, 2010