MySQL如何添加用户 和 分配权限?(亲测可用)

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用户登录是否正常 ,然后检查是否能看到授权访问的库

 

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