1. 程式人生 > 資料庫 >mysql8.0.x建立使用者及授權

mysql8.0.x建立使用者及授權

一,mysql8.x建立使用者及授權

mysql> use mysql;

建立資料庫

mysql> create database db_demo;

建立使用者

”rick“為要建立的使用者名稱;localhost表示只允許本地登入,若把localhost改為“%”則表示任何機器都執行連線;“123456"代表使用者登入密碼;

mysql> create user ‘rick’@‘localhost’ identified by ‘123456’;

授權使用者連線某資料庫

mysql> grant all privileges on db_demo.* to ‘rick’@’%’ with grant option;

mysql> flush privileges;

二,新使用者授權成功後,用Navicate連線失敗

​​

原因:mysql8 之前的版本中加密規則是mysql_native_password,而在mysql8之後,加密規則是caching_sha2_password,解決問題方法有兩種,一種是升級navicat驅動,一種是把mysql使用者登入密碼加密規則還原成mysql_native_password.

解決辦法:修改加密規則,執行以下命令,問題解決;

mysql> alter user ‘rick’@’%’ identified with mysql_native_password by ‘123456’;