mysql用户管理教程(创建用户/删除用户/修改密码/授权用户)

发布时间:2020-05-06编辑:脚本学堂
本文介绍了mysql用户管理的方法,mysql用户管理实例,mysql中创建用户、删除用户、修改密码、授权用户的例子,需要的朋友参考下.

mysql用户管理

1. 登录mysql
 

#1. 以root用户登录mysql服务 
$ mysql -uroot -p 
# 输入mysql root用户密码 
#2. 查看拥有哪些库,并切换到mysql库下 
mysql> show databases; 
+--------------------+ 
| database           | 
+--------------------+ 
| information_schema | 
| cacti              | 
| mysql              | 
| test               | 
+--------------------+ 
4 rows in set (0.00 sec) 
#3. 查看当前用户 
mysql> select user,host,password from user; 
+-----------+---------------+-------------------------------------------+ 
| user      | host          | password                                  | 
+-----------+---------------+-------------------------------------------+ 
| root      | localhost     | *23ae809ddacaf96af0fd78ed04b6a265e05aa257 | 
| root      | futeng-oracle |                                           | 
| root      | 127.0.0.1     |                                           | 
|           | localhost     |                                           | 
|           | futeng-oracle |                                           | 
| cactiuser | localhost     | *23ae809ddacaf96af0fd78ed04b6a265e05aa257 | 
| xiaoqi    | %             | *777fc8d6c72fc57d2cb6f21589a3ee6f7f6d5962 | 
+-----------+---------------+-------------------------------------------+ 
7 rows in set (0.00 sec) 
 

2. 创建用户
未指定host则表示该用户fueng可以在任何主机上连接该mysql服务。
 

mysql> create user futeng identified by '密码'; 
mysql> flush privileges; 
 

指定host则表示用户只能在localhost也就是本机访问mysql<!--endfragment-->
 

create user futeng@localhost identified by '密码'; 
flush privileges;  

3. 修改密码
 

mysql> update user set password=password('新密码') where user="用户" and host="位置"; 
#位置可指定ip、localhost或者*表示任意主机 
 

4. 授权
 

#赋futeng用户在本机访问的所有权限 
grant all privileges on *.* to futeng@localhost; 
#赋远程访问的权限 
grant all privileges on *.* to 'futeng'@'%' with grant option;  

5. 删除用户
 

delete from user where user="futeng" and host="localhost";