- Notifications
You must be signed in to change notification settings - Fork298
MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. Documentation & Download:http://dev.mysql.com/doc/connector-python/en
License
mysql/mysql-connector-python
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
MySQL Connector/Python enables Python programs to access MySQL databases, usingan API that is compliant with thePython Database API Specification v2.0(PEP 249) - We refer to it as theClassic API.
It also contains an implementation of theXDevAPI- An Application Programming Interface for working with theMySQL Document Store.
Connector/Python contains the classic and XDevAPI connector APIs, which areinstalled separately. Any of these can be installed from a binaryor source distribution.
Binaries are distributed in the following package formats:
On the other hand, the source code is distributed as a compressed filefrom which a wheel package can be built.
The recommended way to install Connector/Python is viapip,which relies on WHEEL packages. For such a reason, it is the installation procedurethat is going to be described moving forward.
Please, refer to the official MySQL documentationConnector/Python Installation toknow more about installing from an RPM, or building and installing a WHEEL package froma source distribution.
Before installing a package withpip, it is strongly suggestedto have the most recentpip
version installed on your system.If your system already haspip
installed, you might need to update it. Or you can usethestandalone pip installer.
Theclassic API can be installed via pip as follows:
$ pip install mysql-connector-python
similarly, theXDevAPI can be installed with:
$ pip install mysqlx-connector-python
Please refer to theinstallation tutorialfor installation alternatives of the XDevAPI.
Connector packages included in MySQL Connector/Python allow you to installoptional dependencies to unleash certain functionalities.
# 3rd party packages to unleash the telemetry functionality are installed$ pip install mysql-connector-python[telemetry]
similarly, for the XDevAPI:
# 3rd party packages to unleash the compression functionality are installed$ pip install mysqlx-connector-python[compression]
This installation option can be seen as a shortcut to install all thedependencies needed by a particular feature. Mind that this is optionaland you are free to install the required dependencies by yourself.
Options for the Classic connector:
- dns-srv
- gssapi
- fido2
- telemetry
Options for the XDevAPI connector:
- dns-srv
- compression
importmysql.connector# Connect to servercnx=mysql.connector.connect(host="127.0.0.1",port=3306,user="mike",password="s3cre3t!")# Get a cursorcur=cnx.cursor()# Execute a querycur.execute("SELECT CURDATE()")# Fetch one resultrow=cur.fetchone()print("Current date is: {0}".format(row[0]))# Close connectioncnx.close()
importmysqlx# Connect to serversession=mysqlx.get_session(host="127.0.0.1",port=33060,user="mike",password="s3cr3t!")schema=session.get_schema("test")# Use the collection "my_collection"collection=schema.get_collection("my_collection")# Specify which document to find with Collection.find()result=collection.find("name like :param") \ .bind("param","S%") \ .limit(1) \ .execute()# Print documentdocs=result.fetch_all()print(r"Name: {0}".format(docs[0]["name"]))# Close sessionsession.close()
- MySQL Connector/Python Developer Guide
- MySQL Connector/Python X DevAPI Reference
- MySQL Connector/Python Forum
- MySQL Public Bug Tracker
- Slack (Sign-up required if you do not have an Oracle account)
- Stack Overflow
- Oracle Blogs
There are a few ways to contribute to the Connector/Python code. Please referto thecontributing guidelines for additional information.
Please refer to theREADME.txt andLICENSE.txtfiles, available in this repository, for further details.
About
MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. Documentation & Download:http://dev.mysql.com/doc/connector-python/en
Resources
License
Security policy
Uh oh!
There was an error while loading.Please reload this page.