1, download mysql-connector-python-2.0.4 pythoin access MySQL need to have customers, this is the library to connect MySQL
After decompression, such as:
Double-click Lib
Take windows as an example to copy MySQL to lib\site-packages Linux to find Site-packages
By completing the 2 steps above, you can connect to the database properly.
2, connecting the database code
Config = { 'User':'python', 'Password':'123456', 'Host':'localhost', 'Port': 3306, 'Database':'py_db'}conn= Mysql.connector.connect (* *config)
# Specify oil mark cursor=conn.cursor () SQL="INSERT INTO Py_user (username,passwd,groupid) VALUES ('%s ', '%s ',%s)"% ('DDD','123','1')
Cursor.execute (SQL)
# Commit transactions only INNDB support transactions
Conn.commit ()
Ok! So far, as long as you know the point of MySQL curd can complete the basic operation!
Pythoin Access MySQL