Thanks to visit codestin.com
Credit goes to pypi.org

Skip to main content

Pure Python MySQL Driver

Project description

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:
  • 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, ('[email protected]', '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, ('[email protected]',))
        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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymysql-1.1.2.tar.gz (48.3 kB view details)

Uploaded Source

Built Distribution

pymysql-1.1.2-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

Details for the file pymysql-1.1.2.tar.gz.

File metadata

  • Download URL: pymysql-1.1.2.tar.gz
  • Upload date:
  • Size: 48.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for pymysql-1.1.2.tar.gz
Algorithm Hash digest
SHA256 4961d3e165614ae65014e361811a724e2044ad3ea3739de9903ae7c21f539f03
MD5 abb9c2e708ca71c6534cc04b7e4a8f86
BLAKE2b-256 f5ae1fe3fcd9f959efa0ebe200b8de88b5a5ce3e767e38c7ac32fb179f16a388

See more details on using hashes here.

File details

Details for the file pymysql-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: pymysql-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 45.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.12

File hashes

Hashes for pymysql-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b1d89711dd51f8f74b1631fe08f039e7d76cf67a42a323d3178f0f25762ed9
MD5 02df6e322d43af6d0e0e54704c363b5d
BLAKE2b-256 7c4cad33b92b9864cbde84f259d5df035a6447f91891f5be77788e2a3892bce3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page