Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NotificationsYou must be signed in to change notification settings

mysql/mysql-connector-python

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.

Features

Installation

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.

Installation Options

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

Classic

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()

XDevAPI

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()

Additional Resources

Contributing

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

License

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

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp