查詢所有用戶
-- 方式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; 查詢用戶權(quán)限:all表示所有權(quán)限,select表示只查權(quán)限,update表示只改權(quán)限,delete表示只刪權(quán)限等。
-- 方式1 mysql> show grants for "user"@"host"; mysql> show grants for "root"@"localhost"; -- 方式2 mysql> select * from mysql.user where user='root'\G; 添加授權(quán)用戶(新創(chuàng)建的用戶,默認(rèn)情況下是沒有任何權(quán)限的):使用root用戶登錄數(shù)據(jù)庫
命令格式如下: mysql> create user "haidon" identified by "123456"; -- 此時密碼為123456,host值為%。 mysql> create user "haidon"@"%" identified by "123456"; -- 此時密碼為123456 分配用戶權(quán)限(給用戶授權(quán))
命令格式如下: 常用的權(quán)限類型有以下幾種: -- 允許訪問所有數(shù)據(jù)庫下的所有表 mysql> grant all privileges on *.* to '用戶名'@'指定ip' identified by '用戶密碼' ; -- 允許訪問指定數(shù)據(jù)庫下的所有表 mysql> grant all privileges on test.* to '用戶名'@'指定ip' identified by '用戶密碼' ; -- 允許訪問指定數(shù)據(jù)庫下的指定表 mysql> grant all privileges on test.test to '用戶名'@'指定ip' identified by '用戶密碼' ; mysql> grant all privileges on tornado.* to 'haidon'@'%' identified by '123456'; 收回用戶權(quán)限(使用root用戶操作)
mysql> revoke select on tornado.* from "haidon"@"%"; mysql> revoke all on tornado.* from "haidon"@"%"; 刪除授權(quán)用戶
mysql> drop user "haidon"@"%"; -- 刪除方法1 mysql> delete from mysql.user where user="haidon"; -- 刪除方法2 刷新權(quán)限
mysql> flush privileges; |
|