Preface: Python If you want to connect to MySQL to install the relevant driver, fortunately the driver on the MySQL website can be downloaded to.
Here is a version of Conetos7 I saved myself
Http://yunpan.cn/cLACS7VurfaE4 Access Password 2e26
Example:
#!/usr/bin/python#!coding:utf-8ImportMysql.connector fromMysql.connectorImportErrorCodedefCREATE_DB (host='127.0.0.1', port=3306,user='Admin', password='131417', database='Studio'): Config={ 'Host': Host,'Port':p Ort,'User': User,'Password':p Assword,'Database':d Atabase}Try: Conn=mysql.connector.connect (* *config)exceptMysql.connector.error,err:ifErr.errno = =ErrorCode. Er_access_denied_error:Print 'access_denied_error Something is worng your name or password' elifErr.errno = =ErrorCode. Er_bad_db_error:Print 'database is NOT exists' Else: PrintErrElse: Print 'linked to database ...'cursor=conn.cursor () create_db='CREATE database if not exists tempdb character set UTF8;'Cursor.execute (create_db)Print 'database been created ...'conn.close ()if __name__=="__main__": create_db ()
Python---Connect to MySQL first page