1. 程式人生 > 實用技巧 >MySQL使用者管理(建立使用者,檢視使用者,刪除使用者,修改密碼)

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)