一、創建用戶並授權
1、登錄mysql
mysql -u root -q
2、創建數據庫
create database dbdata;//以創建dbdata為例
3、創建用戶
創建user01,只能本地訪問
create user user01@'localhost' identified by 'password';
創建user02,可以遠程訪問
create user user02@'%' identified by 'password'
4、修改用戶密碼
以user01為例:
set password for 'user01'@'localhost'=password('anotherpassword')
5、授權
授予user01管理dbdata的全部權限
grant all privileges on dbdata.* to user01;
授予user02查看權限,並修改密碼
grant select on *.* to 'user02'@'%' identified by 'anotherpassword';
二、設置mysql允許遠程連接(ubuntu系統)
1、 sudo vi /etc/mysql/my.cnf
2、注釋掉如下兩行:
bind-address=127.0.0.1
skip-network(mysql5.6版本里沒有這行)
3、sudo service mysql restart
結合一中的授權,被授權用戶可以遠程訪問