pycharm连接MySQL数据库后出现“Unknown column 'authentication_string' in 'field list'”怎么解决
这个问题通常是由于MySQL版本的不同所致。从MySQL 8.0开始,密码字段名称由“password”更改为“authentication_string”,这导致在连接MySQL 8.0数据库时出现错误。
要解决此问题,你可以尝试以下两种方法:
在连接MySQL时,添加auth_plugin参数并设置为'caching_sha2_password'。例如:
import mysql.connector
cnx = mysql.connector.connect(user='root', password='password', host='localhost', database='mydatabase', auth_plugin='caching_sha2_password')
这个参数告诉MySQL连接器使用“caching_sha2_password”认证插件,以兼容新版本MySQL的密码字段名称变更。
如果第一种方法不起作用,可以尝试更新mysql-connector-python驱动程序。你可以尝试使用pip升级mysql-connector-python,具体命令为:pip install mysql-connector-python --upgrade