import MySQLdb
conn = MySQLdb.connect(host='192.168.3.94',
user='root',
passwd='123456',
port=3306,
charset='utf8')
conn.select_db('test')
cur = conn.cursor()
a = cur.execute('select * from users;')
print(a)
conn.close()
报错:
_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'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> FLUSH PRIVILEGES;
这里的'root'@'%'
,是经过我修改后的,默认应该为'root'@'localhost'
可以输入SQL命令查看:
mysql> use mysql;
mysql> select host,user from user;
想要将它从localhost
改为%
只需要:
mysql> update user set host = '%' where user = 'root';
mysql> flush privileges;