MySQL創建用戶,並設置指定訪問數據庫


一、創建用戶並授權

1. 登錄mysql 

mysql -u root -q
輸入密碼
2. 創建數據庫(已有數據庫就不需要建立)

create database newDB;//以創建newDB為例
3. 創建用戶

創建userone,只能本地訪問

 create user userone@'localhost' identified by 'password';
創建usertwo,可以遠程訪問

 create user usertwo@'%' identified by 'password';

'%' - 所有情況都能訪問
‘localhost’ - 本機才能訪問
’111.222.33.44‘ - 指定 ip 才能訪問

4. 修改用戶密碼

以userone為例:

 set password for 'userone'@'%'=password('1234')
5. 為用戶授權

授予userone管理newDB的全部權限 

grant all privileges on dbdata.*@'%' to userone identified by '1234';
授予userone全部數據庫權限,並修改密碼

 grant all on *.* to 'usertwo'@'%' identified by '123456';


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM