您好,登錄后才能下訂單哦!
新建一個用戶admin1對所有的庫表完全權限,允許從任何地方訪問,密碼設為123456
Query OK, 0 rows affected, 1 warning (0.00 sec)
語法為
grant 權限列表 on 庫名.表名 用戶名@“用戶地址” identified by " 密碼" [ with grant opion ];
mysql> grant all on . to admin2@"%" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
all 匹配所有權限
. 匹配所有庫和表
” %“ 匹配所有主機
授權用戶admin3 允許對192.168.4.0/24網段訪問
mysql> grant all on . to admin3@'192.168.4.0/24' identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
對用戶admin4在daydb4.user1僅有查詢權限 登錄密碼為123456
mysql> grant select on daydb4.user1 to admin4@"localhost" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
授權admin5 允許本機訪問,對daydb4任何表有查詢 更改 插入 刪除 權限 密碼123456
mysql> grant select,update,delete,insert on daydb4.* to admin4@"localhost" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)
用戶查看自己的授權
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
root 查看其他人用戶的授權
show grant for 用戶名@“客戶端地址”;
mysql> show grants for admin4@"localhost" \g;
+----------------------------------------------------------------------------------------------+
| Grants for admin4@localhost |
+----------------------------------------------------------------------------------------------+
| GRANT USAGE ON . TO 'admin4'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON daydb4
.* TO 'admin4'@'localhost' WITH GRANT OPTION |
| GRANT SELECT ON daydb4
.user1
TO 'admin4'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)
用戶鏈接后修改密碼
set password=password("新密碼");
[root@MySQL50 ~]# mysql -uadmin4 -p654321
[root@MySQL50 ~]# mysql -uadmin4 -p654321
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.7.17 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。