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查看權限,並修改密碼  

    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

結合一中的授權,被授權用戶可以遠程訪問 


免責聲明!

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



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