[MySQL database principle] connect to MySQL database in Python3.7

1. Install mysql-connector-python

To connect to the MySQL database "test" in Python, you can use the "mysql-connector-python" package. First, make sure the package is installed. It can be installed using the pip command:

pip install mysql-connector-python
或
pip install mysql-connector-python -i https://pypi.tuna.tsinghua.edu.cn/simple

insert image description here

2. Connect to the MySQL database

Be sure to open the database, and then, in the Python code, you can use the following code to connect to the database test:

import mysql.connector

Guess you like

Origin blog.csdn.net/weixin_41194129/article/details/130071386