MySQL用户管理(创建用户,查看用户,删除用户,修改密码)

1)创建用户并设置密码

mysql> create user lhd@'172.16.1.%' identified by '123';
Query OK, 0 rows affected (0.02 sec)

2)查看用户

mysql> select user,host from mysql.user;
+--------+------------------------+
| user   | host                   |
+--------+------------------------+
| qiudao | 10.0.0.0/24            |
| lhd    | 10.0.0.0/255.255.255.0 |
| lhd    | 172.16.1.%             |
| root   | localhost              |
+--------+------------------------+
4 rows in set (0.00 sec)

3)删除用户

mysql> drop user qiudao@'10.0.0.0/24';
Query OK, 0 rows affected (0.00 sec)

4)修改用户密码

#1.方式一:命令行修改密码
[root@db02 /service]# mysqladmin -uroot -p password
Enter password: 123456
New password: 123
Confirm new password: 123

#2.方式二:授权的方式修改密码
mysql> grant all on *.* to lhd@'10.0.0.0/255.255.255.0' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

#3.方式三:更新数据库密码
mysql> update mysql.user set password=PASSWORD('123456') where user='lhd' and host='172.16.1.%';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

#4.方式四:直接设置密码
mysql> set password=PASSWORD('123456');
Query OK, 0 rows affected (0.00 sec)

 

posted @ 2020-10-25 19:46  六月OvO  阅读(185)  评论(0编辑  收藏  举报