Python is a commonly used computer language. In actual operations, we will involve the actual operations related to connecting Python to the database. If you are interested in or have doubts about the actual operation solution for connecting Python to the database, you can browse the following articles.
1. Connection Between Python and mysql Databases
To connect Python to MySQL, you can use the MySQL_python module to first determine whether to install python. In the command mode, import Python and then start checking:
Python 2.5.1 (r5.1: 54863, May 2 2007, 16:56:35)
- [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
- Type "help", "copyright", "credits" or "license"
for more information.
- >>> import MySQLdb
- Traceback (most recent call last):
- File "", line 1, in
- ImportError: No module named MySQLdb
- >>> exit()
If you see the preceding
- "ImportError: No module named MySQLdb"
Note: In shell, the output is case-sensitive. You can also run the following commands to test your Database Configuration:
- >>> from django.db import connection >>>
cursor = connection.cursor()
If no error message is displayed, your database configuration is correct. Otherwise, you must check the error information to correct the error. The above code is an example of the code before connecting Python to the mysql database.
Install the mysql_python Module
Download and install MySQLdb on the official website
MySQLdb version:
- (win)MySQL-python-1.2.2.win32-py2.6.exe
Directly run the installation and follow the steps below to install
- $ tar zxvf MySQL-python-1.2.2.tar.gz
- $ cd MySQL-python-1.2.2
- $ python setup.py build
- $ python setup.py install
Attachment:
- libguide40.dll.zip(77.3 KB)
- libmmd.dll.zip(169 KB)
- libmySQL.dll.zip(861 KB)
The above is an introduction to the connection between python and mysql databases in the python database. I hope you will gain some benefits.