MySQL服務(wù)器的用戶權(quán)限管理
-- 授權(quán)一個(gè)用戶(zhangsan)密碼123,可以對(duì)所有的庫(kù)坝锰,所有的表做所有操作粹懒。
mysql> grant all on . to zhangsan@'%' identified by '123';
Query OK, 0 rows affected (0.17 sec)
--刷新生效,否則就要重啟MySQL服務(wù)才可以顷级。
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
--瀏覽當(dāng)前MySQL用戶信息
mysql> select user,host,password from mysql.user;
+----------+-----------------+-------------------------------------------+
| user | host | password |
+----------+-----------------+-------------------------------------------+
| root | localhost | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| root | 127.0.0.1 | |
| | localhost | |
| zhangsan | % | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| admin | 192.168.112.132 | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+----------+-----------------+-------------------------------------------+
5 rows in set (0.00 sec)
-- 移除一些權(quán)限
-- revoke:只刪除了用戶權(quán)限凫乖,但沒(méi)有刪除這個(gè)用戶
mysql> revoke insert,delete on . from admin@192.168.112.132 identified by'123';
-- 查看指定用戶的權(quán)限信息
mysql> show grants for xbb@localhost;
+------------------------------------------------------------------------------------------------------------+
| Grants for xbb@localhost |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON . TO 'xbb'@'localhost' IDENTIFIED BY PASSWORD '*23AE809DDACAF96AF0FD78ED04B6A265E05AA257' |
+------------------------------------------------------------------------------------------------------------+
--drop user:刪除了整個(gè)用戶及其權(quán)限(包括數(shù)據(jù)字典中的數(shù)據(jù))
mysql> drop user 'xbb'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | 127.0.0.1 |
| debian-sys-maint | localhost |
| root | localhost |
| root | wangxg |
+------------------+-----------+
4 rows in set (0.00 sec)