mysql 新建用户,授权,删除用户,修改密码

来源:互联网 发布:c专家编程,微盘 编辑:程序博客网 时间:2024/06/07 20:58

一.用户基本操作

1.创建用户 

登陆:

mysql> mysql -u root -p

新建用户

mysql> CREATE USER test IDENTIFIED BY '123456';

刷新系统权限表:

 mysql> flush privileges;
test表示要创建的用户名,,后面的123456表示密码
此建立的用户可在任何主机登陆。
创建用户时,限制在固定地址登陆,比如localhost 登陆:
mysql> CREATE USER test@localhost IDENTIFIED BY '123456';

2.查看用户信息
mysql> select host,user from mysql.user; 

 mysql> show grants for username@localhost;


3.更改用户密码
mysql>update mysql.user set password=password('新密码') where User="test" and Host="localhost";mysql>flush privileges;

4.删除用户
mysql> DELETE FROM user WHERE user="test" and host="192.168.1.48";mysql>flush privileges;


二. 用户权限操作

1.查看用户权限

查看当前用户权限

mysql>show grants;


根据名字和主机ip查询用户权限

mysql> select host,user from mysql.user where user='username' and host='hostname'; 

 mysql> show grants for username@hostname;

2.用户授权

mysql> grant all privileges on *.*  to  'test'@'192.168.1.48' identified by '123456' with grant option;
刷新系统权限表:
 mysql> flush privileges;

格式:

       all priviliges  表示所有权限

       *.* 表示所有 数据库 所有表
       'test'@'192.168.1.48' 表示 从192.168.1.48主机登陆的test用户
       identified by '123456'  表示 test用户的密码

       with grant option  表示该用户可以将这些权限 赋予其它用户

3. 撤销用户权限

mysql>revoke all on *.* from username@hostname;mysql>flush privileges;



0 0
原创粉丝点击