Pythoin Access MySQL

Source: Internet
Author: User

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

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.