To avoid security risks in MySQL, rename the default root user.
Using the Rename user command to modify the root username failed,
Hint Error: 1396 (HY000): Operation RENAME USER failed for ' root ' @ '% '
Modified successfully using the User table under 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 ' @ '% '
However, it is no problem to rename a normal user with the same command.
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)