Skip to main content

A self-contained Python driver for communicating with MySQL servers, using an API that is compliant with the Python Database API Specification v2.0 (PEP 249).

Project description

https://img.shields.io/pypi/v/mysql-connector-python.svg https://img.shields.io/pypi/pyversions/mysql-connector-python.svg https://img.shields.io/pypi/l/mysql-connector-python.svg

MySQL Connector/Python enables Python programs to access MySQL databases, using an API that is compliant with the Python Database API Specification v2.0 (PEP 249) - We refer to it as the Classic API.

Features

Installation

The recommended way to install Connector/Python is via pip.

Make sure you have a recent pip version installed on your system. If your system already has pip installed, you might need to update it. Or you can use the standalone pip installer.

$ pip install mysql-connector-python

Installation Options

Connector packages included in MySQL Connector/Python allow you to install optional dependencies to unleash certain functionalities.

# 3rd party packages to unleash the telemetry functionality are installed
$ pip install mysql-connector-python[telemetry]

This installation option can be seen as a shortcut to install all the dependencies needed by a particular feature. Mind that this is optional and you are free to install the required dependencies by yourself.

Available options:

  • dns-srv

  • gssapi

  • fido2

  • telemetry

Sample Code

import mysql.connector

# Connect to server
cnx = mysql.connector.connect(
    host="127.0.0.1",
    port=3306,
    user="mike",
    password="s3cre3t!")

# Get a cursor
cur = cnx.cursor()

# Execute a query
cur.execute("SELECT CURDATE()")

# Fetch one result
row = cur.fetchone()
print("Current date is: {0}".format(row[0]))

# Close connection
cnx.close()

Additional Resources

Contributing

There are a few ways to contribute to the Connector/Python code. Please refer to the contributing guidelines for additional information.

License

Please refer to the README.txt and LICENSE.txt files, available in this repository, for further details.

Supported by

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