对mysql.user进行手工操作,比如添加新用户或更改用户的旧密码后,需用flush privileges刷新MySQL的系统权限相关表,否则会出现拒绝访问! mysql>
create user yangql identified by 'yangql'; Query OK, 0 rows affected (0.02 sec)
[root@rac3 home]#
mysql -uyangql -pyangql 以root用户登录,手工修改mysql.user表,这里演示更新用户的密码,对于插入新建用户操作类似! mysql>
update mysql.user set password=password('yql') where user='yangql'; Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
select * from mysql.user where user='yangql'; +------+--------+------------------+-------------+
| Host | User | Password | Select_priv |
+------+--------+------------------+-------------+
| % | yangql | 66d7dc1c3dfc53e6 | N |
+------+--------+------------------+-------------+
没有使用flush privilges之前,可以使用老的密码进行登录。 [root@rac3 home]#
mysql -uyangql -pyangql mysql> flush privilges;//刷新系统权限相关的表 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
Query OK, 0 rows affected (0.00 sec)
[root@rac3 ~]#
mysql -uyangql -pyangql ERROR 1045 (28000): Access denied for user 'yangql'@'localhost' (using password: YES) [root@rac3 ~]#
mysql -uyangql -pyql Welcome to the MySQL monitor. Commands end with ; or \g.
还有一种方法,就是重新启动mysql服务器,来使新设置生效。