Rename Root @ localhost username in MySQL?



The syntax is as follows to rename Root @localhost

UPDATE MySQL.user SET user = ‘yourNewRootName’ WHERE user = 'root';

To understand the above concept, let us check all the user names and host. The query is as follows

mysql> select user,host from MySQL.user;

The following is the output

+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Manish           | %         | | User2            | %         | | mysql.infoschema | %         | | mysql.session    | %         | | mysql.sys        | %         | | root             | %         | | @UserName@       | localhost | | Adam Smith       | localhost | | John             | localhost | | John Doe         | localhost | | User1            | localhost | | am               | localhost | | hbstudent        | localhost | | mysql.infoschema | localhost | | mysql.session    | localhost | +------------------+-----------+ 16 rows in set (0.00 sec)

The following is the query to rename the user ‘root’ to some other name

mysql> UPDATE mysql.user set user = 'MyRoot' where user = 'root'; Query OK, 1 row affected (0.13 sec) Rows matched: 1 Changed: 1 Warnings: 0

Let us check the user ‘root’ has been updated with new name ‘MyRoot’ or not. The query is as follows

mysql> select user,host from MySQL.user;

The following is the output

+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Manish           | %         | | MyRoot           | %         |   | User2            | %         | | mysql.infoschema | %         | | mysql.session    | %         | | mysql.sys | % | | @UserName@ | localhost | | Adam Smith | localhost | | John | localhost | | John Doe | localhost | | User1 | localhost | | am | localhost | | hbstudent | localhost | | mysql.infoschema | localhost | | mysql.session | localhost | +------------------+-----------+ 16 rows in set (0.00 sec)

Look at the sample output, the root has been updated with new name “MyRoot” successfully.

Updated on: 2019-07-30T22:30:25+05:30

667 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements