在安装mysql8.0并配置以后,使用phpmyadimin连接mysql会有以下两种常见的错误:
1.mysqli_real_connect(): (HY000/2002): No such file or directory
这是因为不能使用localhost要用ip登陆
*解决方法:
1)phpmyadmin的配置文件【config.sample.inc.php】改成【config.inc.php】
2)用终端或者sublime都可
找到—
c
f
g
[
′
S
e
r
v
e
r
s
′
]
[
cfg['Servers'][
cfg[′Servers′][i][‘host’] = ‘localhost’;
改成—
c
f
g
[
′
S
e
r
v
e
r
s
′
]
[
cfg['Servers'][
cfg[′Servers′][i][‘host’] = ‘127.0.0.1’;
这个时候如果安装的是mysql8.0以上的版本就会出现另两个个问题:
2.mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]
3.mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client
这是因为无法请求身份验证
*解决方法:
1)先用终端打开mysql
2)查看host
当中root的host为localhost
3)使用密码更改身份验证插件
以下示范了错误和正确的用法:
语法规则:
alter user ‘root’@‘localhost’ identified with mysql_native_password by ‘自己设置的数据库密码’
*如果在2)步中的查询root的host为"%"
则‘root‘@’localhost’ ➡️ ‘root‘@’%’