查詢所有用戶
-- 方式1
mysql> select host, user, password from mysql.user; -- 5.7版本之前的
mysql> select host, user, authentication_string from mysql.user; -- 5.7版本之后的,包括5.7
-- 方式2
mysql> select distinct concat('User: ''',user,'''@''',host,''';') as query from mysql.user;
查詢用戶權限:all表示所有權限,select表示只查權限,update表示只改權限,delete表示只刪權限等,
-- 方式1 mysql> show grants for "user"@"host"; mysql> show grants for "root"@"localhost"; -- 方式2 mysql> select * from mysql.user where user='root'\G;
添加授權用戶(新創建的用戶,默認情況下是沒有任何權限的):使用root用戶登錄資料庫
命令格式如下:
mysql> create user "用戶名"@"IP地址" identified by "密碼";
mysql> create user "haidon" identified by "123456"; -- 此時密碼為123456,host值為%, mysql> create user "haidon"@"%" identified by "123456"; -- 此時密碼為123456
分配用戶權限(給用戶授權)
命令格式如下:
mysql> grant 權限型別 on 資料庫名.表名 to '用戶名'@'ip地址' identified by '用戶密碼' with grant option;
常用的權限型別有以下幾種:
all privileges:所有權限,
select:讀取權限,
create:創建權限,
delete:洗掉權限,
update:更新權限,
drop:洗掉資料庫、資料表權限,
-- 允許訪問所有資料庫下的所有表 mysql> grant all privileges on *.* to '用戶名'@'指定ip' identified by '用戶密碼' ; -- 允許訪問指定資料庫下的所有表 mysql> grant all privileges on test.* to '用戶名'@'指定ip' identified by '用戶密碼' ; -- 允許訪問指定資料庫下的指定表 mysql> grant all privileges on test.test to '用戶名'@'指定ip' identified by '用戶密碼' ; mysql> grant all privileges on tornado.* to 'haidon'@'%' identified by '123456';
識訓用戶權限(使用root用戶操作)
mysql> revoke select on tornado.* from "haidon"@"%"; mysql> revoke all on tornado.* from "haidon"@"%";
洗掉授權用戶
mysql> drop user "haidon"@"%"; -- 洗掉方法1 mysql> delete from mysql.user where user="haidon"; -- 洗掉方法2
重繪權限
mysql> flush privileges;
https://www.cnblogs.com/sidesky/p/10650354.html
https://www.cnblogs.com/zhangjianqiang/p/10019809.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/232941.html
標籤:其他
上一篇:MySQL的統計資訊學習總結
下一篇:MySQL事務。
