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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章