One-click connection to the mysql driver using python (for windows) and pythonmysql
I spent one afternoon on the mysql driver and shared the solution.
1: manually install the driver
This is a nightmare. We recommend that you use automatic installation.
2: Automatic Installation
Download the automatic installation package, http://www.bkjia.com/softs/73369.html
Double-click to install! After installation is complete. You can operate the database normally.
Eg:
Import mysqldb
Con = mysqldb. connect (host = 'localhost', user = 'root', passwd = 'root', db = 'test ')
Cursor = con. cursor ()
SQL = "select * from test"
Cursor.exe cute (SQL)
Alldata = cursor. fetchall ()
If alldata:
For rec in alldata:
Print rec [0]
Cursor. close ()
Con. close ()
If a friend uses pydev in eclispe, the import mysqldb will fail because eclipse cannot identify the driver automatically. If you use this method, please use Baidu.
Two drivers are available for windows. For other versions, download them from the official website.
: Https://pypi.python.org/pypi/MySQL-python/