標籤:5.5 where str too 所有許可權 com alt toolbar copy
測試環境:CentOS6.8 和 MySQL5.5.4
一 需求
在項目開發的過程中可能需要開放自己的資料庫給別人,但是出於安全的考慮,不能同時開放自己伺服器裡的其他資料庫。那麼可以建立一個使用者,賦予該使用者特定的資料庫許可權。
二 實現
1 建立使用者
// root 使用者登陸 MySQLmysql -uroot -pEnter password:// 建立使用者mysql>insert into mysql.user(Host,User,Password) values("localhost","buff",password("buff"));// 重新整理系統許可權表mysql>flush privileges;
這樣就建立了一個名為:buff,密碼為:buff 的使用者。
2 登陸測試
mysql>exit// 使用者 buff 登陸 MySQLmysql -ubuff -pEnter password:mysql>
說明建立的使用者 buff 登陸成功。
3 使用者授權
// root 使用者登陸 MySQLmysql -uroot -pEnter password:// 為使用者 buff 建立一個資料庫 bluebuffmysql>create database bluebuff;// 授權使用者 buff 擁有資料庫 bluebuff 的所有許可權mysql>grant all privileges on bluebuff.* to [email protected] identified by ‘buff‘;mysql>flush privileges;
4 登入測試
// 使用者 buff 登陸資料庫mysql -ubuff -pEnter privileges:// 顯示資料庫mysql>show databases;
結果如所示,說明為使用者 buff 授權成功
5 修改使用者 buff 的密碼
// root 使用者登陸 MySQLmysql -uroot -pEnter password:// 修改使用者 buff 的密碼mysql>update table mysql.user set password=password(‘buffer‘) where User=‘buff‘ and Host=‘localhost‘;
mysql>flush privileges;
6 刪除使用者
// root 使用者登陸 MySQLmysql -uroot -pEnter password:// 刪除使用者 buffmysql>delete from mysql.user where User = ‘buff‘ and Host = ‘localhost‘;mysql>flush privileges;
7 刪除資料庫
mysql>drop database bluebuff;
MySQL中建立使用者指派許可權