Home >Backend Development >Python Tutorial >How to connect Python to MySQL

How to connect Python to MySQL

silencement
silencementOriginal
2019-05-24 16:35:5736657browse

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.

How to connect Python 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

How to connect Python to MySQL

## 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:

How to connect Python to MySQL

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

How to connect Python to MySQL

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn