PHP连接Mysql8.0报错:Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = manuscript and table_name = migratio
ns and table_type = ‘BASE TABLE’)

发生这种错误,是由于MySQL 8默认使用了新的密码验证插件:caching_sha2_password,而之前的PHP版本中所带的mysqlnd无法支持这种验证。

  • 解决方法:

1.找到mysql的配置文件my.cnf(如果是window系统,找到mysql.ini文件,默认是在C:\ProgramData\MySQL\MySQL Server 8.0\文件夹下)

2.在 [mysqld]下加入 default-authentication-plugin=mysql_native_password 一行

3.flush privileges 刷新

4.进入mysql 修改登入mysql用户的登录验证方式

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '密码';
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐