用mysql -uroot -p连接数据库时报错
[root@localhost ~]# mysql -uroot -p
Enter password:
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
解决方法:
编辑/etc/my.cnf,在里面添加一条免密登录
[root@localhost ~]# vi /etc/my.cnf
进去之后,
MySQL [(none)]> flush privileges;(刷新权限)
MySQL [(none)]> alter user 'root'@'localhost' identified with mysql_native_password by 'root';
退出来,删除在/etc/my.cnf中添加的行,输入密码登录即可
解析:由于MySQL8.0.12版本默认的认证方式是caching_sha2_password,连接不上的原因在于连接数据库工具不支持该格式的密码。