Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change root username in MySQL

Tags:

mysql

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.

like image 315
Adrian Ber Avatar asked Oct 23 '13 10:10

Adrian Ber


People also ask

How do I change my MySQL root username and password?

In the mysql client, tell the server to reload the grant tables so that account-management statements work: mysql> FLUSH PRIVILEGES; Then change the 'root'@'localhost' account password. Replace the password with the password that you want to use.

How do I find my MySQL root username?

user SET Password=PASSWORD('new password') WHERE User='root'; FLUSH PRIVILEGES; mysqladmin -u root -p shutdown Note: Once you shutdown mysqladmin, you would be seeing the safe mode exits in Terminal 1. sudo service mysql start That's it and it works like a charm with the new password!

How do I find my MySQL root username and password?

In order to recover the password, you simply have to follow these steps: Stop the MySQL server process with the command sudo service mysql stop. Start the MySQL server with the command sudo mysqld_safe –skip-grant-tables –skip-networking & Connect to the MySQL server as the root user with the command mysql -u root.

How do I change my localhost root password?

Use the following procedure to set a root password. To change the root password, type the following at the MySQL/MariaDB command prompt: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges; exit; Store the new password in a secure location.


1 Answers

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';
like image 171
Adrian Ber Avatar answered Sep 21 '22 21:09

Adrian Ber