Connect python to the Mysql database and pythonmysql Database

Source: Internet
Author: User

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 ();

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.