一、創建用戶並授權
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';