 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements
 