Home >Database >Mysql Tutorial >What is mysql-connector
"mysql-connector" is the driver officially provided by mysql, which can be used to connect and use mysql; you can use the "pip install mysql-connector" command to install it, and use "import mysql.connector" to test whether the installation is successful.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Use mysql-connector to connect to MySQL. mysql-connector is the driver officially provided by MySQL.
We can use the pip command to install mysql-connector:
python -m pip install mysql-connector
Use the following code to test whether the mysql-connector is installed successfully:
demo_mysql_test.py: import mysql.connector
Execute the above code, if no error is generated , indicating that the installation is successful.
Note: If your MySQL is version 8.0, the password plug-in verification method has changed. The early version is mysql_native_password, and the 8.0 version is caching_sha2_password, so you need to make some changes:
Modify my. ini configuration:
[mysqld] default_authentication_plugin=mysql_native_password
Then execute the following command under mysql to change the password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
The example is as follows:
Create a database connection
Yes Use the following code to connect to the database:
demo_mysql_test.py: import mysql.connector mydb = mysql.connector.connect( host="localhost", # 数据库主机地址 user="yourusername", # 数据库用户名 passwd="yourpassword" # 数据库密码 ) print(mydb)
Recommended learning: mysql video tutorial
The above is the detailed content of What is mysql-connector. For more information, please follow other related articles on the PHP Chinese website!