MySQL中建立使用者指派許可權

來源:互聯網
上載者:User

標籤: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中建立使用者指派許可權

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.