MySQL基本授权操作

本文介绍MySQL权限的基本操作。

授权
MySQL用户包括user和host两部分。

user与host是一起出现的,即权限指的是某个用户在某个主机或某些主机上的权限。

首先,创建用户:

mysql> CREATE USER 'root'@'%' IDENTIFIED  by 'mysql123456';
1
接着,授权权限:

mysql> GRANT ALL on *.* to 'root'@'%';
Query OK, 0 rows affected (0.00 sec)
1
2
具体权限,是指某个DB下某个table的权限。
这里授权'root'@'%' 操作所有DB所有tabe的权限。

查看授权
查看’root’@’%'的授权:

mysql> show grants for 'root'@'%';
+-------------------------------------------------------------+
| Grants for root@%                                           |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

1
2
3
4
5
6
7
8
查看授权用户
mysql> select * from mysql.user;
1
查看指定用户

mysql> select * from mysql.user where user='root'\G
*************************** 1. row ***************************
                  Host: localhost
                  User: root
... ...

         max_questions: 0
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: *xxx
      password_expired: N
 password_last_changed: 2018-10-10 14:42:12
     password_lifetime: NULL
        account_locked: N
*************************** 2. row ***************************
                  Host: %
                  User: root
... ...
           max_updates: 0
       max_connections: 0
  max_user_connections: 0
                plugin: mysql_native_password
 authentication_string: xxx
      password_expired: N
 password_last_changed: 2018-10-10 14:47:32
     password_lifetime: NULL
        account_locked: N
2 rows in set (0.01 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
撤销权限
撤销某个用户的授权:

REVOKE ALL on orchestrator.* FROM 'orchestrator_server'@'10.23.211.199';
1
删除用户:

delete from mysql.user where user='orchestrator_server' and host='10.23.211.199' ;
flush privileges ;
————————————————
版权声明:本文为CSDN博主「翔云123456」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/lanyang123456/article/details/105187628
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值