
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can I change root username in MySQL?
To change the root username in MySQL, you need to use UPDATE and SET command. The syntax is as follows −
UPDATE user set user = ’yourNewUserName’ WHERE user = ’root’;
To understand the above syntax, let us switch the database to MySQL using USE command.
The query is as follows to switch the database.
mysql> use mysql; Database changed
Now list all the users from MySQL.user table. The query is as follows −
mysql> select user from MySQL.user;
The following is the output −
+------------------+ | user | +------------------+ | Manish | | User2 | | mysql.infoschema | | mysql.session | | mysql.sys | | root | | Adam Smith | | User1 | | am | +------------------+ 9 rows in set (0.04 sec)
Look at the sample output, we have username ‘root’. Change the username root to some other name using UPDATE command.
Let us change the username ‘root’ to ‘myRoot’. The query is as follows −
mysql> update user set user = 'myRoot' where user = 'root'; Query OK, 0 rows affected (0.00 sec) Rows matched: 0 Changed: 0 Warnings: 0
List all users from MySQL.user table to see the username ‘root’ have been changed to ‘myRoot’. The query is as follows to list all users from MySQL.user table.
mysql> select user from MySQL.user;
The following is the output −
+------------------+ | user | +------------------+ | Manish | | User2 | | myRoot | | mysql.infoschema | | mysql.session | | mysql.sys | | Adam Smith | | User1 | | am | +------------------+ 9 rows in set (0.00 sec)
Look at the above table, ‘root’ username has been changed to ‘myRoot’.
- Related Articles
- Rename Root @ localhost username in MySQL?
- How can I restore the MySQL root user full privileges?
- How to reset or change the MySQL root password?
- How can I change the storage engine of a MySQL table?
- How can I change the default sort order of MySQL tables?
- How can I resize the root window in Tkinter?
- Should I name the username field in my MySQL table “name” or “user_name”?
- How can I change the value of an instance of a row in MySQL table?
- How can I change the field name in MongoDB?
- How can I change the name of an existing column from a MySQL table?
- How can I view cascades in MySQL?
- How to get username using ID from another table in MySQL database?
- How can we change MySQL AUTO_INCREMENT starting number?
- How can I start MySQL Server?
- How can I shutdown MySQL Server?
