本地环境:
python2.7.15
MySQL8.0
MySQL-python 1.2.5
执行:
>>> import MySQLdb
>>> conn = MySQLdb.connect(host="localhost",user="root",passwd="123456",db="sunck")
遇到报错:
_mysql_exceptions.OperationalError: (1251, 'Client does not support authentication protocol requested by server; consider upgrading MySQL client')
解决办法:
命令行输入:
mysql -u root -p
输入密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> FLUSH PRIVILEGES;
更改密码后需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问,还有一种方法,就是重新启动mysql服务器,来使新设置生效。