phpmyadmin连接MySQL8.0报错#2054 - The server requested authentication method unknown to the client

发生这种错误,是由于MySQL 8默认使用了新的密码验证插件:caching_sha2_password,而之前的PHP版本中所带的mysqlnd无法支持这种验证
有几种方法:1.升级PHP版本,PHP7.xx有支持MySQL8.0的插件认证
2.修改配置文件my.cnf 使数据库启用兼容的加密方式
我们这里讲第二种方法
安装MySQL8.0的过程这里就不赘述了,可以参考我的另一篇博客

2.1

whereis mysql
//查看mysql所存在的目录

在这里插入图片描述

cd /etc/mysql
//切换到/etc/mysql下
ls

在这里插入图片描述
我们对my.cnf进行修改

vim my.cnf
//如果权限不够的话可以切换到root用户进行操作

在最底下添加下面的代码

[mysqld]
default_authentication_plugin= mysql_native_password
//更改为原来的验证方式

然后保存退出,vim的命令可自行百度
重启mysql服务

sudo service mysql restart

除了上述这种方法,还可以用另一种

2.2

用命令行 mysql -u root -p 登录mysql
输入:

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码'; 
FLUSH PRIVILEGES;

再用phpmyadmin登录管理mysql,报错消失了。
大功告成

已标记关键词 清除标记
我快炸裂了,网上能找到的方法我都试过了,都没有用,附上我的配置 /** * MySQL hostname or IP address * * @global string $cfg['Servers'][$i]['host'] */ $cfg['Servers'][$i]['host'] = '127.0.0.1'; /** * MySQL port - leave blank for default port * * @global string $cfg['Servers'][$i]['port'] */ $cfg['Servers'][$i]['port'] = ''; /** * Path to the socket - leave blank for default socket * * @global string $cfg['Servers'][$i]['socket'] */ $cfg['Servers'][$i]['socket'] = ''; /** * Use SSL for connecting to MySQL server? * * @global boolean $cfg['Servers'][$i]['ssl'] */ $cfg['Servers'][$i]['ssl'] = false; /** * Path to the key file when using SSL for connecting to the MySQL server * * @global string $cfg['Servers'][$i]['ssl_key'] */ $cfg['Servers'][$i]['ssl_key'] = null; /** * Path to the cert file when using SSL for connecting to the MySQL server * * @global string $cfg['Servers'][$i]['ssl_cert'] */ $cfg['Servers'][$i]['ssl_cert'] = null; /** * Path to the CA file when using SSL for connecting to the MySQL server * * @global string $cfg['Servers'][$i]['ssl_ca'] */ $cfg['Servers'][$i]['ssl_ca'] = null; /** * Directory containing trusted SSL CA certificates in PEM format * * @global string $cfg['Servers'][$i]['ssl_ca_path'] */ $cfg['Servers'][$i]['ssl_ca_path'] = null; /** * List of allowable ciphers for SSL connections to the MySQL server * * @global string $cfg['Servers'][$i]['ssl_ciphers'] */ $cfg['Servers'][$i]['ssl_ciphers'] = null; /** * MySQL 5.6 or later triggers the mysqlnd driver in PHP to validate the * peer_name of the SSL certifcate * For most self-signed certificates this is a problem. Setting this to false * will disable the check and allow the connection (PHP 5.6.16 or later) * * @link https://bugs.php.net/68344 * @global string $cfg['Servers'][$i]['ssl_verify'] */ $cfg['Servers'][$i]['ssl_verify'] = true; /** * Use compressed protocol for the MySQL connection * * @global boolean $cfg['Servers'][$i]['compress'] */ $cfg['Servers'][$i]['compress'] = false; /** * MySQL control host. This permits to use a host different than the * main host, for the phpMyAdmin configuration storage. If left empty, * $cfg['Servers'][$i]['host'] is used instead. * * @global string $cfg['Servers'][$i]['controlhost'] */ $cfg['Servers'][$i]['controlhost'] = ''; /** * MySQL control port. This permits to use a port different than the * main port, for the phpMyAdmin configuration storage. If left empty, * $cfg['Servers'][$i]['port'] is used instead. * * @global string $cfg['Servers'][$i]['controlport'] */ $cfg['Servers'][$i]['controlport'] = ''; /** * MySQL control user settings (this user must have read-only * access to the "mysql/user" and "mysql/db" tables). The controluser is also * used for all relational features (pmadb) * * @global string $cfg['Servers'][$i]['controluser'] */ $cfg['Servers'][$i]['controluser'] = ''; /** * MySQL control user settings (this user must have read-only * access to the "mysql/user" and "mysql/db" tables). The controluser is also * used for all relational features (pmadb) * * @global string $cfg['Servers'][$i]['controlpass'] */ $cfg['Servers'][$i]['controlpass'] = ''; /** * Authentication method (valid choices: config, http, signon or cookie) * * @global string $cfg['Servers'][$i]['auth_type'] */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; ------------------------------------------------------ /** * MySQL user * * @global string $cfg['Servers'][$i]['user'] */ $cfg['Servers'][$i]['user'] = 'root'; /** * MySQL password (only needed with 'config' auth_type) * * @global string $cfg['Servers'][$i]['password'] */ $cfg['Servers'][$i]['password'] = '123456'; --------------------------------------------------- ** * whether to allow root login * * @global boolean $cfg['Servers'][$i]['AllowRoot'] */ $cfg['Servers'][$i]['AllowRoot'] = true; /** * whether to allow login of any user without a password * * @global boolean $cfg['Servers'][$i]['AllowNoPassword'] */ $cfg['Servers'][$i]['AllowNoPassword'] = true; ----------------------------------------------------- 给带哥们磕头了,砰砰砰
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页