Home > Article > Backend Development > How to connect Python to MySQL
How to connect python to mysql: You can use the pymysql tool to connect to mysql. Specific methods: 1. Execute the [pip install pymysql] command to install pymysql; 2. Execute the [mysql -u root -p] command to connect to mysql.
This article introduces the method of connecting Python3 to MySQL’s third-party library-PyMySQL
Introduction to PyMySQL
PyMySQL is a library used to connect to the MySQL server in the Python3.x version. PyMySQL can also be used to connect to the MySQL database in Django.
pymysql installation
##1. Install pymysql through pip,Enter cmd and enter pip install pymysql , Press Enter and wait for the installation to complete
## After the installation is completed, the relevant information as shown in the figure appears, indicating that the installation is successful.
MySQL connection database
You can use MySQL binary mode to enter the mysql command prompt to connect to the MySQL database
The following is a simple example of connecting to the mysql server from the command line:
After successful login, the mysql> command prompt window will appear, and you can execute any SQL statement on it. After the above command is executed, the successful login output is as follows
In In the above example, we used the root user to log in to the mysql server. Of course, you can also use other mysql users to log in. If the user rights are sufficient, any user can perform SQL operations in the mysql command prompt window.
The above is the detailed content of How to connect Python to MySQL. For more information, please follow other related articles on the PHP Chinese website!