Connect python to the Mysql database and pythonmysql Database
1. Download http://dev.mysql.com/downloads/connector/python/
Because Python is installed on 3.4, You need to download the following mysql-connector-python: After the download is successful: 2. Install mysql-connector-python, and you will find that the installation is quiet, everything happens to you. In fact, many things have happened. I have observed that there are more writes under the python installation directory: There are more things in the mysql folder, mysql_connecter _.... -info3. You can use python to connect to the Mysql database ~~ The test code is as follows:
Import mysql. connectorconfig = {'host': '2017. 0.0.1 ', # default 127.0.0.1 'user': 'root', 'Password': '000000', 'Port': 123456, # default value: 3306 'database ': 'School _ data', 'charset': 'utf8' # utf8 by default} try: cnn = mysql. connector. connect (** config); print ("connection successful"); cour = cnn. cursor (); value = ('20140901', 'asddd '); SQL = "" insert into dw (dwdm, dwmc) values (% s, % s) "; cour.exe cute (SQL, value); # The following sentence is very important. If I leave this sentence missing, no error is reported, and no data is inserted, it will crash ~~~ Cnn. commit (); Response t mysql. connector. Error as e: print ('connect fails! {} '. Format (e) finally: cour. close (); cnn. close ();