Using Python to operate MySQL Databases

Source: Internet
Author: User
Tags python mysql

First, you must first have the Python MySQL connection module MySQLdb
It has been installed by default in CentOS 5.4, but not in Ubuntu. You need to manually install it as follows:

: Http://

An example that can cover 80% application scenarios:

Import MySQLdb # create a link con = MySQLdb. connect (host = "", port = 3306, user = "root", passwd = "123456", db = "test") # generate a cursor, used to execute the SQL statement cursor = con. cursor () # Run the SQL statement SQL = "SELECT * FROM Users" cursor.exe cute (SQL) # Fetch all results from the cursor into a sequence and close the connection # Get the returned value and close the connection results = cursor. fetchall ()

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: 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.