I'm running MySQL in Ubuntu, default installation.
How can I change the username from root
to another one, let's say admin
? Preferably from the command line.
I'm running MySQL in Ubuntu, default installation.
How can I change the username from root
to another one, let's say admin
? Preferably from the command line.
After connecting to MySQL run
use mysql;
update user set user='admin' where user='root';
flush privileges;
That's it.
If you also want to change password, in MySQL < 5.7, run
update user set password=PASSWORD('new password') where user='admin';
before flush privileges;
. In MySQL >= 5.7, the password
field in the user
table was renamed to authentication_string
, so the above line becomes:
update user set authentication_string=PASSWORD('new password') where user='admin';
root
and admin
for the same root account. –
Moleskins I just wanted to say that for me, there was no column 'password'.
To change password, the correct field was authentication_string
So the command is
update user set authentication_string=PASSWORD('new password') where user='admin';
I'm no MySQL expert, so I'm not sure exactly why, but what I said is correct, at least in my case.
For example, you can change the username root
to john
as shown below. *I recommend to use RENAME USER ...
because directly modifying mysql.user
is sometimes problematic. *You probably need to log in with the user root
:
RENAME USER 'root'@'localhost' to 'john'@'localhost';
Or:
UPDATE mysql.user SET User='john' WHERE User='root';
FLUSH PRIVILEGES;
Then, you can log in to MySQL:
mysql -u john -p
© 2022 - 2025 — McMap. All rights reserved.