Xixi provides support for three versions of Python 2.7/3.2/3.3, can handle large data packets, and supports connection compression protocols and SSL.
MySQL Connector/Python is the Python driver officially provided by MySQL to connect to the MySQL database.
I've been learning Python recently and found that Python's many class libraries bring great convenience to Python development.
Since Mysql is used in the project, I considered trying to use Python to call Mysql to facilitate writing some small program code for debugging.
The steps are as follows:
1) Go to Python.org to find the package used. I downloaded mysql.connector.
2) Code writing, import mysql.connector:
Mainly divided into 5 steps:
(a) Connect to the database: conn = mysql.connector.connect(host='localhost', user='root',passwd='pwd',db='test')
(b) Get the operation handle: cursor = conn.cursor()
(c) Execute sql: cursor.execute(sql), cursor.executemany(sql, val)
(d) Get query results: alldata = cursor.fetchall()
(e) Close the connection: cursor.close(), conn.close()
it works
it works
it works