mysql 用戶和權(quán)限管理 首先mysql root用戶登錄 [root@xx ~]# mysql -u root -p Enter password: 輸入密碼 切換數(shù)據(jù)庫(kù) mysql use mysql; 創(chuàng)建一個(gè)用戶 mysql insert into user(host,user,password) values ("%","game",password("xxxxx"));Query OK, 1 row aff
mysql 用戶和權(quán)限管理[root@xx ~]# mysql -u root -p Enter password: 輸入密碼
切換數(shù)據(jù)庫(kù)
mysql> use mysql;
創(chuàng)建一個(gè)用戶
mysql> insert into user(host,user,password) values ("%","game",password("xxxxx")); Query OK, 1 row affected, 4 warnings (0.00 sec)
host表示可以進(jìn)行連接的主機(jī)
% 通配符,表示任何主機(jī),允許遠(yuǎn)程連接時(shí)一般這么設(shè)置
也可以設(shè)置某個(gè)ip段: x.x.x.%
localhost表示只能本機(jī)連
刷新系統(tǒng)權(quán)限
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)
mysql> create database game; Query OK, 1 row affected (0.06 sec)
分配game數(shù)據(jù)庫(kù)的所有權(quán)限給game用戶
mysql> grant all privileges on game.* to game@"%" identified by 'xxxx'; Query OK, 0 rows affected (0.00 sec)
all 表示dba權(quán)限 包括 select, insert, update, delete,create,alter,execute ...
game.*表示game下的所有對(duì)象,也可以 *.*表示所有數(shù)據(jù)庫(kù)對(duì)象
如果想指定部分權(quán)限給一用戶,可以這樣來(lái)寫:
mysql>grant select,update on game.* to game@localhost identified by 'xxxx';
刷新系統(tǒng)權(quán)限
mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
修改指定用戶密碼
mysql>update mysql.user set password=password('新密碼') where User="game" and Host="%";
刪除指定用戶
mysql>DELETE FROM user WHERE User="game" and Host="localhost"; mysql>flush privileges;
查看用戶權(quán)限
mysql> show grants for game; +-----------------------------------------------------------------------------------------------------+ | Grants for game@% | +-----------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'game'@'%' IDENTIFIED BY PASSWORD '*6830234338985B955032067DE689AFC3ECD27EEA' | | GRANT ALL PRIVILEGES ON `game`.* TO 'game'@'%' | +-----------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
收回用戶權(quán)限
revoke all on game.* from game@%;
分配權(quán)限是 grant 權(quán)限 to 用戶,收回是revoke 權(quán)限 from 用戶。
修改用戶或用戶相關(guān)的權(quán)限等,都要執(zhí)行flush privileges才生效
mysql> quit
Bye
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com