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:
Gadfly
MSQL
Mysql
PostgreSQL
Microsoft SQL Server 2000
Informix
Interbase
Oracle
Sybase
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 "test.py", line 3, in <module>mysqldbimporterror:no module named MySQLdb
To install MYSQLDB, visit Sourceforge.net/projects/mysql-python, (Linux platform can access: Pypi.python.org/pypi/mysql-python) 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 setup.py build$ python setup.py Install
Note: Make sure that you have root permissions to install the above modules.