How to connect Python to MySQL

silencement
Release: 2020-09-17 13:23:12
Original
36499 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!