MySQL查看登錄用戶以及修改密碼和創建用戶以及授權


1、mysql查看當前登錄用戶,當前數據庫:

select user();
select database();

2、修改root或其他用戶密碼

update mysql.user set password=password('新密碼') where user='用戶名';
flush privileges; //此為刷新權限

3、建庫

create database `庫名` DEFAULT CHARSET utf8 COLLATE utf8_general_ci;  

4、創建用戶

新增用戶,並只限本地登錄
insert into mysql.user(Host,User,Password) values("localhost","用戶名",password("密碼"));
flush privileges; 

新增用戶,外網可登錄
insert into mysql.user(Host,User,Password) values("%","用戶名",password("密碼"));
flush privileges; 

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

grant all privileges on `庫名或*`.* to '用戶名'@'%' identified by '密碼';  
flush privileges;  

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

grant all privileges on `庫名或*`.* to 'testuser'@'localhost' identified by 'userpasswd';  
flush privileges;  

7、針對test數據庫創建一個無任何權限的用戶

grant usage on test.* to zhangsan@localhost identified by 'zhangsan1';
賦予某個權限
grant select on test.* to zhangsan@localhost;

8、撤銷一個用戶對某數據庫的所有權限

revoke all privileges on test.* from zhangsan@localhost;

 


免責聲明!

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



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