MySQL 添加用戶 給用戶添加權限


搬運出處: https://www.cnblogs.com/wuxunyan/p/9095016.html

1. 新建用戶

格式:create user "username"@"host" identified by "password";

host="localhost" 允許本地登錄,host="ip" 允許ip地址,host="%",允許所以ip登錄

mysql->create user 'test'@'localhost' identified by '123456';

mysql->create user 'test'@'192.168.1.11' identified by '123456'; 

mysql
->create user 'test'@'%' identified by '123456';

2. 刪除用戶

格式:drop user 'username'@'host';

(5)授權

格式:grant privileges on databasename.tablename to 'username'@'host' IDENTIFIED BY 'PASSWORD';

  /*授予用戶通過外網IP對於該數據庫的全部權限*/

  grant all privileges on `test`.* to 'test'@'%' ;

  /*授予用戶在本地服務器對該數據庫的全部權限*/

  grant all privileges on `test`.* to 'test'@'localhost';   

   grant select on test.* to 'user1'@'localhost';  /*給予查詢權限*/

   grant insert on test.* to 'user1'@'localhost'; /*添加插入權限*/

   grant delete on test.* to 'user1'@'localhost'; /*添加刪除權限*/

   grant update on test.* to 'user1'@'localhost'; /*添加權限*/

  flush privileges; /*刷新權限*/

 

/*授予用戶通過外網IP對於該數據庫的全部權限*/
grant all privileges on `test`.* to 'test'@'%' ;
/*授予用戶在本地服務器對該數據庫的全部權限*/
grant all privileges on `test`.* to 'test'@'localhost';   
grant select on test.* to 'user1'@'localhost';  /*給予查詢權限*/
grant insert on test.* to 'user1'@'localhost'; /*添加插入權限*/
grant delete on test.* to 'user1'@'localhost'; /*添加刪除權限*/
grant update on test.* to 'user1'@'localhost'; /*添加權限*/
flush privileges; /*刷新權限*/


免責聲明!

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



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