mysqli_connect: authentication method unknown to the client [caching_sha2_password]

mysql-8.0 新特性

  1. 认证方法更新为了: caching_sha2_password
  2. 字符集改成了默认: utf8mb4
mysqli_connect: authentication method unknown to the client [caching_sha2_password]

解决办法:

将认证方式和字符集改为之前的方式

  1. 编辑mysql配置文件
vim  /etc/my.cnf

[mysqld]
default_authentication_plugin=mysql_native_password
character_set_server =utf8
  1. 重启mysql 服务
service mysqld restart
  1. 创建数据库
create database dbname charset=utf8 collate=utf8_general_ci;

或更新数据库

alter database dbname charset=utf8 collate=utf8_general_ci;
  1. 创建用户,赋予权限
create user 'root'@'%' identified with mysql_native_password by '123456';
grant all on dbname.* to 'root'@'%';
flush privileges;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章