python安装mysql官方驱动:
python -m pip install mysql-connector
由于我安装的是mysql8.0,在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password。
ALTER USER admin@'%' IDENTIFIED WITH mysql_native_password BY 'admin'
import mysql.connector mydb = mysql.connector.connect( host="127.0.0.1", user="admin", passwd="admin", database="apple", auth_plugin='mysql_native_password' ) mycursor = mydb.cursor() mycursor.execute("SHOW TABLES")