MySQL Connector/Python Developer's Guide (working on translation)

This article has been updated for a long time

This article is translated from: https://dev.mysql.com/doc/connector-python/en/

If there is any inappropriate translation in this article, please point it out in the comments below this article ^_^

Copyright statement: original works, reprinting is permitted, please be sure to indicate the original source of the article and author information in the form of hyperlinks when reprinting. Otherwise held liable.

Summary

This manual describes how to install and configure MySQL Connector/Python. MySQL Connector/Python is a stand-alone driver that communicates between Python and MySQL services. This manual will also describe how to use it to develop database applications.

For details on the changes for each release of Connector/Python, see MySQL Connector/Python Release Notes .

For legal information, see Legal Notices .

For help with MySQL, visit the MySQL Forums or the MySQL Mailing Lists , where you can discuss discussions with other MySQL users.

Get documentation for other MySQL products, including translations in other languages ​​and downloadable versions in various formats, including HTML and PDF, from the MySQL Documentation Library

Some notes on licensing information: MySQL products may contain third-party software, use licensing information, if you are using the commercial release version of MySQL Connector/Python, please click this document for licensing information, which includes information about the commercial release version included. License information for third-party software. . If you are using the community-released version of MySQL Connector/Python, please click this document for licensing information, which includes licensing information for third-party software that includes the community-released version.

Document generation date: 2017-06-01 (Revision code: 52416)

1 Introduction to MySQL Connector/Python

MySQL Connector/Python enables your Python programs to communicate with MySQL databases using an API that conforms to the Python Database API Specification v2.0 (PEP 249) . This API is written in pure Python with the exception of the Python Standard Library and has no dependencies.

For detailed changes to each release of Connector/Python, see MySQL Connector/Python Release Notes .

MySQL Connector/Python support includes the following:

  • Almost all functionality is provided by MySQL Server (including MySQL Server version 5.7).
  • Both Python and MySQL data types can convert their corresponding parameter values ​​back and forth, such as Python's datetime and MySQL's DATETIME. For convenience, you can choose automatic conversion, or turn off the best performance.
  • All MySQL extensions to standard SQL syntax.
  • The compression protocol can compress the data stream between the client and the server.
  • Connect using TCP/IP sockets and Unix sockets on Unix.
  • Using SSL connections can make TCP/IP more secure.
  • Outside of the standard library, the stand-alone Connector/Python driver does not require the MySQL client library or some other Python module.

For information on which Python versions each MySQL Connector/Python version works with, see 3 Connector/Python Versions

Note: Connector/Python does not support authentication methods for older versions of MySQL Server, which means that versions of MySQL prior to 4.1 will not work

2 MySQL Connector/Python Developer's Guide

The following guide covering MySQL application aspects should not be too difficult for a person with a Python development background:

  • for safety

3 Connector/Python version

The following table summarizes the available Connector/Python versions. For some official versions to be released, the development version before it is no longer supported for a long time.

Connector/Python version MySQL Server version Python version Connector status
2.2 5.7、5.6、5.5 3.3 or higher, 2.7 Developer Milestones
2.1 5.7、5.6、5.5 3.3 or higher, 2.7, 2.6 Recommended version
2.0 5.7、5.6、5.5 3.3 or higher, 2.7, 2.6 official version, support
1.2 5.7、5.6、5.5(5.1、5.0、4.1) 3.1 or higher, 2.7, 2.6 official version, support

Note: As we all know, if MySQL server and Python version are to work together, Connector/Python must be used as a bridge to connect the two together

Note: Connector/Python does not support authentication methods for older versions of MySQL Server, which means that versions of MySQL prior to 4.1 will not work

4 Connector/Python installation

Connector/Python runs on any platform that has Python installed, and Python is preinstalled on Unix and Unix-like systems such as Linux, OS X, and FreeBSD. On Microsoft operating systems, you can download the Python installation package from the Python Download website for installation, if necessary, download and install Python before you try to install Connector/Python.

Note: Connector/Python requires Python in your system path, because Connector/Python will fail to install when Python is not loaded

4.1 Get Connector/Python

4.2 Connector/Python binary installation

4.3 Connector/Python source code installation

4.4 Verify that Connector/Python is successfully installed

5 Connector/Python code example

These code examples illustrate how to use MySQL Connector/Python to connect to MySQL Server and develop Python applications and scripts.

5.1 Connect to MySQL using Connector/Python

The constructor connect() creates a service that connects to MySQL and returns a MySQLConnection object.

The following example shows how to connect to the MySQL server:

import mysql.connector

cnx = mysql.connector.connect(user='scott', password='tiger',
                              host='127.0.0.1',
                              database='employees')
cnx.close()

Translation is not finished...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324893730&siteId=291194637