<b>對mysql.user進行手工操作,比如添加新使用者或更改使用者的舊密碼後,需用flush privileges重新整理MySQL的系統權限相關表,否則會出現拒絕通路!</b>
以root身份登入資料庫,建立使用者yangql
mysql> <b>create user yangql identified by 'yangql';</b>
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Bye
<b>測試連接配接。</b>
[root@rac3 home]# <b>mysql -uyangql -pyangql</b>
mysql> show databases;
+--------------------+
| Database |
| information_schema |
| test |
2 rows in set (0.00 sec)
<b>以root使用者登入,手工修改mysql.user表,這裡示範更新使用者的密碼,對于插入建立使用者操作類似!</b>
[root@rac3 home]#<b> mysql </b>
mysql> show databases;
| latin |
| lyz |
| momo |
| mysql |
| test2 |
| yangdb |
| yangutf |
9 rows in set (0.00 sec)
mysql> <b>update mysql.user set password=password('yql') where user='yangql';</b>
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> <b>select * from mysql.user where user='yangql';</b>
+------+--------+------------------+-------------+
| Host | User | Password | Select_priv |
| % | yangql | 66d7dc1c3dfc53e6 | N |
1 row in set (0.00 sec)
<b>沒有使用flush privilges之前,可以使用老的密碼進行登入。</b>
<b>執行重新整理操作:</b>
[root@rac3 home]# mysql
<b>mysql> flush privilges;//重新整理系統權限相關的表</b>
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'privilges' at line 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
<b>再次使用舊密碼登入</b>
[root@rac3 ~]# <b>mysql -uyangql -pyangql</b>
<b>ERROR 1045 (28000): Access denied for user 'yangql'@'localhost' (using password: YES)</b>
<b>再次使用新密碼登入</b>
[root@rac3 ~]# <b>mysql -uyangql -pyql</b>
Welcome to the MySQL monitor. Commands end with ; or \g.
[root@rac3 ~]#
還有一種方法,就是重新啟動mysql伺服器,來使新設定生效。