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;

你可能感兴趣的:(MySQL)