MySQL database is an interface for Python to connect to the Mysql database. It implements the Python database API specification V2.0 and is based on the MySQL C API. In other words, it uses the most concise Python languageTo control the MYSQL database:
So, what is the MySQL database?
MySQLdb is an interface for Python to connect to the Mysql database. It implements the Python database API specification V2.0 and is based on the MySQL C API.
How to install MySQL database?
In order to write MySQL scripts using DB-API, you must ensure that MySQL is installed. Copy the following code and execute it:
#!/usr/bin/python # -*- coding: UTF-8 -*- import MySQLdb
If the output after execution is as follows, it means you have not installed the MySQLdb module:
Traceback (most recent call last): File "test.py", line 3, in <module> import MySQLdb ImportError: No module named MySQLdb
To install MySQLdb, please visit http://sourceforge. net/projects/mysql-python , (Linux platform can visit: https://pypi.python.org/pypi/MySQL-python) From here, you can choose the installation package suitable for your platform, which is divided into precompiled binary files and Source code installation package.
If you choose the binary file release version, the installation process will be completed with basic installation prompts. If you are installing from source code, you need to switch to the top-level directory of the MySQLdb distribution 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: Please make sure you have root permissions to install the above modules.
The above is the detailed content of Three articles to help you figure out how to learn mysql database and install SQL database. For more information, please follow other related articles on the PHP Chinese website!