網(wǎng)站開發(fā)費(fèi)用如何入賬企點(diǎn)下載
mysql 用戶授權(quán)
1 )概述
- 讓每個(gè)應(yīng)用程序,單獨(dú)開一個(gè)mysql的用戶權(quán)限
- 所有mysql用戶存儲(chǔ)在 mysql庫的user表中
2 ) 多種用戶授權(quán)方式示例
show databases;
use mysql;select user, authentication_string, host from mysql.user;-- 創(chuàng)建和刪除用戶
-- create user '用戶名'@'連接者的ip地址' identified by '密碼';
create user wang@'127.0.0.1' identified by 'root123';
drop user wang@'127.0.0.1';create user zz@'127.0.0.%' identified by 'root123';
drop user zz@'127.0.0.%';
-- 以上是在某個(gè)網(wǎng)段內(nèi)創(chuàng)建用戶create user lee@'%' identified by 'root123';
drop user lee@'%';
-- 以上是在任意的 ip 地址下, 創(chuàng)建用戶create user 'xx'@'%' identified by 'root123';
drop user 'xx'@'%';
3 )修改mysql用戶
rename user '用戶名'@'ip地址' to '新用戶名'@'ip地址'
4 ) 修改mysql密碼
set password for '用戶名'@'ip地址' = PASSWORD('新密碼');
5 )授權(quán)管理
語法
- grant 權(quán)限 on 數(shù)據(jù)庫.表 to ‘用戶’@‘ip地址’
示例
grant all privileges on *.* TO 'xx'@'某ip'; 用戶 xx 擁有所有數(shù)據(jù)庫的所有權(quán)限
grant all privileges on studydb.* TO 'xx'@'某ip'; 用戶xx 擁有數(shù)據(jù)庫 studydb 的所有權(quán)限
grant all privileges on studydb.info TO 'xx'@'某ip'; 用戶xx 擁有數(shù)據(jù)庫 studydb中 info表的所有權(quán)限grant select on studydb.info TO 'xx'@'某ip'; 用戶xx 擁有數(shù)據(jù)庫 studydb 中info表的查詢權(quán)限
grant select, insert on studydb.* TO 'xx'@'某ip'; 用戶xx 擁有數(shù)據(jù)庫 studydb 中info表的查詢和插入權(quán)限flush privileges; -- 將數(shù)據(jù)讀取到內(nèi)存中,從而立即生效,這個(gè)必須要有
對(duì)于權(quán)限的解讀
- all privileges 除grant外的所有權(quán)限
- select 僅查權(quán)限
- select, insert 查和插入權(quán)限
- usage 連接(登錄)權(quán)限,建立一個(gè)用戶,默認(rèn)就會(huì)自動(dòng)授予其usage權(quán)限, 無其他權(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和存儲(chǔ)過程
- file 使用 select info outfile 和 load data infile
- grant option 使用 grant 和 revoke
- index 使用 index
- insert 使用 insert
- lock tables 使用 lock table
- process 使用 show full processlist
查看授權(quán)
- show grants for “用戶”@“ip地址”
- $
show grants for 'xx'@'localhost'
取消授權(quán)
-
revoke 權(quán)限 on 數(shù)據(jù)庫.表 from ‘xx’@‘ip地址’;
-
$
revoke ALL PRILEGES on studydb.* from 'xx'@'localhost';
-
注意
- 這些由運(yùn)維DBA統(tǒng)一管理
- 為每個(gè)項(xiàng)目數(shù)據(jù)庫創(chuàng)建用戶
- 并賦予相關(guān)權(quán)限,
- 開發(fā)人員基本使用不到