1. Install python
Go to the official website to download and install https://www.python.org/downloads/windows/
2. Install the MySQLdb library
(1) Download and install the VC compiler
http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266
(2) Download and install MySQL Connector For C
Note: It must be version 6.0 and must be installed in the default path (C drive)
https://dev.mysql.com/downloads/connector/c/6.0.html
(3) Install pip install MySQL-Python with PIP
3. Use the MySQLdb library
# coding:utf-8 import MySQLdb if __name__ == '__main__': conn = MySQLdb.connect(host = '127.0.0.1', port = 3307, user = 'root', passwd = '', db = 'test') cur = conn.cursor() cur.execute('select * from tb_test1') data = cur.fetchall() cur.close() conn.close() print data
operation result
For more usage methods, please refer to the address
http://www.runoob.com/python/python-mysql.html