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;

 

posted @ 2017-04-05 15:11  弍月关  阅读(12380)  评论(0编辑  收藏  举报