Mysql創建用戶並授權以及開啟遠程訪問
一、創建用戶並授權
1、登錄mysql
mysql -u root -p
2、創建數據庫
create database test;//以創建test為例
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管理test的全部權限
grant all privileges on test.* to user01;
授予user02查看權限,並修改密碼
二、設置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
結合一中的授權,被授權用戶可以遠程訪問
1、登錄mysql
mysql -u root -p
2、創建數據庫
create database test;//以創建test為例
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管理test的全部權限
grant all privileges on test.* to user01;
授予user02查看權限,並修改密碼
grant select on *.* to 'user02'@'%' identified by 'anotherpassword';
授予所有權限
GRANT ALL PRIVILEGES ON *.* TO zhangsan@"%" IDENTIFIED BY "lisi";
二、設置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
結合一中的授權,被授權用戶可以遠程訪問
如果mysql遠程訪問沒有開啟,其它通過遠程訪問如django,mysql客服端均出現如下提示:
Mysql ERROR 1698 (28000) ,特此記錄一下