mysql5.7創立用戶受權刪除用戶撤銷受權。本站提示廣大學習愛好者:(mysql5.7創立用戶受權刪除用戶撤銷受權)文章只能為提供參考,不一定能成為您想要的結果。以下是mysql5.7創立用戶受權刪除用戶撤銷受權正文
一, 創立用戶:
命令:
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
闡明:username - 你將創立的用戶名, host - 指定該用戶在哪個主機上可以登陸,假如是本地用戶可用localhost, 假如想讓該用戶可以從恣意近程主機登陸,可以運用通配符%. password - 該用戶的登陸密碼,密碼可以為空,假如為空則該用戶可以不需求密碼登陸服務器.
例子:
CREATE USER 'dog'@'localhost' IDENTIFIED BY 'password'; CREATE USER 'pig'@'192.168.1.100' IDENDIFIED BY 'password'; CREATE USER 'pig'@'192.168.1.%' IDENDIFIED BY 'password'; CREATE USER 'pig'@'%' IDENTIFIED BY 'password'; CREATE USER 'pig'@'%' IDENTIFIED BY ''; CREATE USER 'pig'@'%';
二,受權:
命令:
GRANT privileges ON databasename.tablename TO 'username'@'host'
闡明: privileges - 用戶的操作權限,如SELECT , INSERT , UPDATE 等(詳細列表見該文最前面).假如要授予所的權限則運用ALL.;databasename - 數據庫名,tablename-表名,假如要授予該用戶對一切數據庫和表的相應操作權限則可用*表示, 如*.*.
例子:
GRANT SELECT, INSERT ON test.user TO 'pig'@'%'; GRANT ALL ON *.* TO 'pig'@'%';
留意:用以上命令受權的用戶不能給其它用戶受權,假如想讓該用戶可以受權,用以下命令:
GRANT privileges ON databasename.tablename TO 'username'@'host' WITH GRANT OPTION;
權限信息用user、db、host、tables_priv和columns_priv表被存儲在MySQL數據庫中(即在名為mysql的數據庫中)。
權限 列 Context
select Select_priv 表
insert Insert_priv 表
update Update_priv 表
delete Delete_priv 表
index Index_priv 表
alter Alter_priv 表
create Create_priv 數據庫、表或索引
drop Drop_priv 數據庫或表
grant Grant_priv 數據庫或表
references References_priv 數據庫或表
reload Reload_priv 服務器管理
shutdown Shutdown_priv 服務器管理
process Process_priv 服務器管理
file File_priv 在服務器上的文件存取
三.設置與更改用戶密碼
命令:
SET PASSWORD FOR 'username'@'host' = PASSWORD('newpassword');假如是以後登陸用戶用SET PASSWORD = PASSWORD("newpassword");
例子:
SET PASSWORD FOR 'pig'@'%' = PASSWORD("123456");
四.撤銷用戶權限
命令:
REVOKE privilege ON databasename.tablename FROM 'username'@'host';
闡明: privilege, databasename, tablename - 同受權局部.
例子: REVOKE SELECT ON *.* FROM 'pig'@'%';
留意: 假設你在給用戶'pig'@'%'受權的時分是這樣的(或相似的):GRANT SELECT ON test.user TO 'pig'@'%',
則在運用REVOKE SELECT ON *.* FROM 'pig'@'%';
命令並不能撤銷該用戶對test數據庫中user表的SELECT 操作.相反,假如受權運用的是GRANT SELECT ON *.* TO 'pig'@'%';
則REVOKE SELECT ON test.user FROM 'pig'@'%
';命令也不能撤銷該用戶對test數據庫中user表的Select 權限.
詳細信息可以用命令SHOW GRANTS FOR 'pig'@'%';
檢查.
五.刪除用戶
命令:
DROP USER 'username'@'host';
六 檢查用戶的受權
mysql> show grants for 'test01'@'localhost'; +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Grants for test01@localhost | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'test01'@'localhost' | | GRANT INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `test001`.* TO 'test01'@'localhost' | +-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.01 sec) mysql> show grants for 'test02'@'localhost'; +-------------------------------------------------------------+ | Grants for test02@localhost | +-------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'test02'@'localhost' | | GRANT ALL PRIVILEGES ON `test001`.* TO 'test02'@'localhost' | +-------------------------------------------------------------+ 2 rows in set (0.00 sec)
以上所述是給大家引見的mysql5.7創立用戶受權刪除用戶撤銷受權,希望對大家有所協助,假如大家有任何疑問請給我留言,會及時回復大家的。在此也十分感激大家對網站的支持!