Skip to main content
Documentation Status https://coveralls.io/repos/PyMySQL/PyMySQL/badge.svg?branch=master&service=github https://img.shields.io/lgtm/grade/python/g/PyMySQL/PyMySQL.svg?logo=lgtm&logoWidth=18

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

License

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

Metadata

Release files for PyMySQLPlus 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyMySQLPlus 1.0.2
File Size Uploaded
PyMySQLPlus-1.0.2.tar.gz 43.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PyMySQLPlus 1.0.2
File Interpreter ABI Platform
PyMySQLPlus-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 87.6 kB

Release files / PyMySQLPlus-1.0.2.tar.gz

Download URL PyMySQLPlus-1.0.2.tar.gz
Size 43.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5b4cdd330675cf7e8f2a77514945438df2d4017cb18dd3cbde513622f40472e6
BLAKE2b-256 checksum
How to use checksums
fe49900a1ce565fb46c2c5a1a887593872c696e5628fd50c1e5d4e0501726886
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.9

Release files / PyMySQLPlus-1.0.2-py3-none-any.whl

Download URL PyMySQLPlus-1.0.2-py3-none-any.whl
Size 43.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
98efab99f6748b03b640263be81804edaab4cd56ff7a038265d79d94fd40115b
BLAKE2b-256 checksum
How to use checksums
b3621a1e26cdaa5492a64050a8cf89ea58edf516714c140b5e898d013abd3804
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.9

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page