Skip to main content

Pure Python MySQL Driver with extended utilities

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, ('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.

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

mysql_conect_python-1.2.0.tar.gz (61.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mysql_conect_python-1.2.0-py3-none-any.whl (60.4 kB view details)

Uploaded Python 3

File details

Details for the file mysql_conect_python-1.2.0.tar.gz.

File metadata

  • Download URL: mysql_conect_python-1.2.0.tar.gz
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for mysql_conect_python-1.2.0.tar.gz
Algorithm Hash digest
SHA256 58ae20c18e4434a5ae9e6d731febd27ccd5fb8d4dce3aad6aef18a3b430a8c83
MD5 3c582b0f8952e648d6e4ca54d419293a
BLAKE2b-256 89dc7a95041119dd9d0c1cf26c0f07f1c6a7325c405f05a99c5734757f6034dc

See more details on using hashes here.

File details

Details for the file mysql_conect_python-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mysql_conect_python-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6caa8cc6076d36faa51741b84e921392b5e3fe0b9f4dfffcd3cdc8f599405d5
MD5 fe3a573c75ff297883fc451b9e62b46a
BLAKE2b-256 c7a8cf87309c893d75400583c49d8120ba7419f79a0d536255fd4c364a247a7a

See more details on using hashes here.

Supported by

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