Using Python to manipulate an instance of MySQL

Source: Internet
Author: User
1. The Python standard Database interface provides the developer with a database application programming interface for Python Db-api,python Db-api.

The Python database interface supports a very great number of databases, and you can choose the database that works for your project:





Microsoft SQL Server 2000





You can access the Python database interface and API to view a detailed list of supported databases.

Different databases you need to download different DB API modules, such as you need to access the Oracle database and MySQL data, you need to download the Oracle and MySQL database modules.

DB-API is a specification. It defines a set of required objects and database access methods to provide a consistent access interface for a wide variety of underlying database systems and a wide variety of database interface programs.

Python's Db-api, which implements the interface for most databases, uses it to connect to each database and manipulate the databases in the same way.

Python DB-API Usage Process:

Introduce API modules.

Gets the connection to the database.

Executes SQL statements and stored procedures.

Close the database connection.

2. How do I install mysqldb?

In order to write MySQL scripts with Db-api, you must make sure that MySQL is already installed. Copy the following code and execute:

#!/usr/bin/python#-*-coding:utf-8-*-import mysqldb

If the output after execution is as follows, it means that you do not have the MySQLdb module installed:

Traceback (most recent): File "", line 3, in <module>mysqldbimporterror:no module named MySQLdb

To install MYSQLDB, visit, (Linux platform can access: From here you can choose the installation package for your platform, which is divided into precompiled binaries and source code installation packages.

If you choose a binary file release, the installation process will complete with the basic installation instructions. If you are installing from source code, you will need to switch to the top-level directory of the MYSQLDB release and type the following command:

$ gunzip mysql-python-1.2.2.tar.gz$ tar-xvf mysql-python-1.2.2.tar$ cd mysql-python-1.2.2$ python build$ python Install

Note: Make sure that you have root permissions to install the above modules.

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.