为了避免mysql中的安全隐患,将默认的root用户重命名。
使用 rename user 命令修改root用户名失败,
提示错误:ERROR 1396 (HY000): Operation RENAME USER failed for 'root'@'%'
改用update mysql用户下的user表后修改成功。
mysql> use mysql;
Database changed
mysql> select host, user, password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 127.0.0.1 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| ::1 | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+-----------+------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> rename user root to admin;
ERROR 1396 (HY000): Operation RENAME USER failed for 'root'@'%'
但用同样的命令重命名普通用户却没问题。
mysql> update user set user='admin' where user='root';
Query OK, 3 rows affected (0.09 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host, user, password from user;
+-----------+-------+-------------------------------------------+
| host | user | password |
+-----------+-------+-------------------------------------------+
| localhost | admin | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| 127.0.0.1 | admin | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| ::1 | admin | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
+-----------+-------+-------------------------------------------+
3 rows in set (0.00 sec)
--转自