DCL(Data Control Language 數(shù)據(jù)庫控制語言)
基礎(chǔ)的數(shù)據(jù)庫安全機制,用于數(shù)據(jù)庫授權(quán)、角色控制等操作
重要的:
grant 授權(quán),為用戶賦予訪問權(quán)限
revoke 取消授權(quán),撤回授權(quán)權(quán)限
用戶管理
創(chuàng)建用戶
create user '用戶名'@'IP地址' identified by '密碼';
刪除用戶
drop user '用戶名'@'IP地址';
修改用戶
rename user '用戶名'@'IP地址' to '新用戶名'@'IP地址' ;
修改密碼
// 第一種方法:
set password for '用戶名'@'IP地址'=Password('新密碼')
// 第二種方法:
alter user '用戶名'@'IP地址' identified by '新密碼';
// 第三種方法(忘記密碼時,必須使用此方法修改密碼):
UPDATE mysql.user SET authentication_string='' WHERE user='root' and host='localhost';
PS:用戶權(quán)限相關(guān)數(shù)據(jù)保存在mysql數(shù)據(jù)庫的user表中,所以也可以直接對其進(jìn)行操作(不建議)
認(rèn)識權(quán)限
all privileges 除grant外的所有權(quán)限
select 僅查權(quán)限
select,insert 查和插入權(quán)限
............................................................................
usage 無訪問權(quán)限
alter 使用alter table
alter routine 使用alter procedure和drop procedure
create 使用create table
create routine 使用create procedure
create temporary tables 使用create temporary tables
create user 使用create user、drop user、rename user和revoke all privileges
create view 使用create view
delete 使用delete
drop 使用drop table
execute 使用call和存儲過程
file 使用select into outfile 和 load data infile
grant option 使用grant 和 revoke
index 使用index
insert 使用insert
lock tables 使用lock table
process 使用show full processlist
show databases 使用show databases
show view 使用show view
update 使用update
reload 使用flush
shutdown 使用mysqladmin shutdown(關(guān)閉MySQL)
super 使用change master、kill、logs、purge、master和set global。還允許mysqladmin調(diào)試登陸
replication client 服務(wù)器位置的訪問
replication slave 由復(fù)制從屬使用
權(quán)限管理
grant 權(quán)限 on 數(shù)據(jù)庫.表 to '用戶'@'IP地址' identified by '密碼'; -- 授權(quán)并設(shè)置密碼
revoke 權(quán)限 on 數(shù)據(jù)庫.表 from '用戶'@'IP地址' -- 取消權(quán)限