MySQL5.7 添加用户、删除用户与授权,创建、删除、切换数据库

创建用户:


create user 'test'@'localhost' identified by 'michael123';

test: 用户名

michael123: 密码

localhost: 只有本机可以访问

create user 'michael'@'%' identified by 'michael123'; 

%:任何电脑都可以访问

create user 'winter'@'9.110.238.211' identified by 'winter123'; 

9.110.238.211:winter只能从这个ip登录

create user 'winter01'@'9.110.238.211' identified by '';

密码为空:winter01不需要密码登陆服务器。

创建、删除、切换数据库

create database mysql01;

drop database mysql01;

use mysql01;

授权:

GRANT ALL ON mysql01.* TO 'michael'@'%'

ALL: 所以权限,也可以单独制定delete, select, update, insert

mysql01: 在这个数据库上的权限

michael:用户

%:任何有michael的电脑上


grant all privileges on mysql01.* to 'winter01'@'%' identified by 'winter123';

创建用户winter01,密码winter123,同时赋给winter01在mysql01数据库上所有的权限


刷新权限

flush privileges;

撤销用户权限

测试用户:

--create user 'michael02'@'%' identified by 'michael123';
--GRANT ALL ON mysql01.* TO 'michael02'@'%';
--GRANT INSERT ON mysql01.* TO 'michael02'@'%';
--GRANT SELECT ON mysql01.* TO 'michael02'@'%';

--flush privileges;

查看michael02的权限

SHOW GRANTS FOR 'michael02'@'%';

撤销michael02所有的权限

REVOKE ALL ON mysql01.* FROM 'michael02'@'%';
--REVOKE INSERT ON mysql01.* FROM 'michael02'@'%';
--REVOKE SELECT ON mysql01.* FROM 'michael02'@'%';


删除用户

drop user 'test'@'localhost';

      命令: DROP USER 'username'@'host';


查看用户的授权


mysql> SHOW GRANTS FOR 'michael02'@'%';
+--------------------------------------------------------+
| Grants for michael02@%                                 |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'michael02'@'%'                  |
| GRANT ALL PRIVILEGES ON `mysql01`.* TO 'michael02'@'%' |
+--------------------------------------------------------+
2 rows in set (0.00 sec)

USAGE:create user时的默认的空权限,只能连库,所以michael02现在的权限是在mysql01数据库上有所有的权限。

 


你可能感兴趣的:(环境配置)