grant all on *.* to [email protected] identified by "passwd" with grant option 該語句將在user表中為[email protected]創(chuàng)建一個記錄,打開所有權(quán)限,因?yàn)檫@里是超級用戶(全局)權(quán)限存儲的地方,要用insert語句做同樣的事情,語句是:
insert into user values("localhost","anyname",password("passwd"), "y","y","y","y","y","y","y","y","y","y","y","y","y","y") 你可能發(fā)現(xiàn)它不工作,這要看你的mysql版本。授權(quán)表的結(jié)構(gòu)已經(jīng)改變而且你在你的user表可能沒有14個權(quán)限列。用show columns找出你的授權(quán)表包含的每個權(quán)限列,相應(yīng)地調(diào)整你的insert語句。 下列g(shù)rant語句也創(chuàng)建一個擁有超級用戶身份的用戶,但是只有一個單個的權(quán)限:
grant reload on *.* to [email protected] identified by "flushpass" 本例的insert語句比前一個簡單,它很容易列出列名并只指定一個權(quán)限列。所有其它列將設(shè)置為缺省的"n":
insert into user (host,password,reload) values("localhost","flush",password("flushpass"),"y") 數(shù)據(jù)庫級權(quán)限用一個on db_name.*子句而不是on *.*進(jìn)行授權(quán):
grant all on sample.* to [email protected] identified by "ruby" 這些權(quán)限不是全局的,所以它們不存儲在user表中,我們?nèi)匀恍枰趗ser表中創(chuàng)建一條記錄(使得用戶能連接),但我們也需要創(chuàng)建一個db表記錄記錄數(shù)據(jù)庫集權(quán)限:
insert into user (host,user,password) values("localhost","boris",password("ruby"))
insert into db values("localhost","sample_db","boris","y","y","y","y","y","y","n","y","y","y")
"n"列是為grant權(quán)限;對末尾的一個數(shù)據(jù)庫級具有with grant option的grant語句,你要設(shè)置該列為"y"。