1.先用root用戶登錄Mysql
mysql -u root -p
2.添加新的用戶
case1:允許本地 IP訪問localhost的Mysql數據庫
create user 'user_test'@'localhost' identified by 'test9527';
case2:允許外網IP訪問數據庫editest,本命令包含上面的命令,是所有的IP都可以訪問該數據庫
create user 'user_test'@'%' identified by 'test9527';
3.用戶創建完成後,刷新授權
mysql> flush privileges;
4.創建一個新的數據庫,(可以用navicat創建)
mysql> create database testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
5.將用戶user_test賦權給數據庫testdb
case1:mysql> grant all privileges on `testdb`.* to 'user_test'@'localhost' identified by 'test9527' with grant option;
case2:mysql> grant all privileges on `testdb`.* to 'user_test'@'%' identified by 'test9527' with grant option;
6.授權
mysql> flush privileges;
7.檢查user_test用戶登錄是否正常 ,然後檢查是否能看到授權訪問的庫