MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL

github.com/PyMySQL/PyMySQL

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.3 ↗ · + Follow · compare 4 versions
423 symbols 1,825 edges 37 files ⚖ MIT 126 documented · 30% updated 6d agov1.2.0 · 2026-05-19★ 7,84412 open issues

Browse by type

Functions 364 Types & classes 57 Endpoints 2
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Documentation Status codecov Ask DeepWiki

PyMySQL

This package contains a pure-Python MySQL and MariaDB client library, based on PEP 249.

Requirements

  • Python -- one of the following:
  • CPython : 3.9 and newer
  • PyPy : Latest 3.x version
  • MySQL Server -- one of the following:
  • MySQL LTS versions
  • MariaDB LTS versions

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

License

PyMySQL is released under the MIT License. See LICENSE for more information.

Core symbols most depended-on inside this repo

browse all functions →

Shape

Method 300
Function 64
Class 57
Route 2

Languages

Python100%

Modules by API surface

pymysql/connections.py63 symbols
pymysql/tests/test_connection.py60 symbols
pymysql/protocol.py44 symbols
pymysql/cursors.py44 symbols
pymysql/tests/test_issues.py28 symbols
pymysql/converters.py23 symbols
pymysql/tests/test_basic.py22 symbols
pymysql/tests/test_auth_state_machine.py18 symbols
pymysql/err.py14 symbols
pymysql/tests/test_converters.py11 symbols
pymysql/_auth.py11 symbols
pymysql/tests/test_DictCursor.py10 symbols

Dependencies from manifests, versioned

PyNaCl1.4.0 · 1×
sphinx8.0 · 1×
sphinx-rtd-theme3.0.0 · 1×

For agents

$ claude mcp add PyMySQL \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page