Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out my root MySQL password?

Tags:

mysql

ubuntu

I just installed MySQL on Ubuntu and the root user can't log in :)

How can I recover or find out my password? Using blank for password does not work.

like image 290
Genadinik Avatar asked Apr 15 '11 23:04

Genadinik


People also ask

What should I do if I forget root password for MySQL?

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 username and password?

In your local system right, go to this url : http://localhost/phpmyadmin/ In this click mysql default db, after that browser user table to get existing username and password.


1 Answers

You can reset the root password by running the server with --skip-grant-tables and logging in without a password by running the following as root (or with sudo):

# service mysql stop # mysqld_safe --skip-grant-tables & $ mysql -u root 
mysql> use mysql; mysql> update user set authentication_string=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root'; mysql> flush privileges; mysql> quit 
# service mysql stop # service mysql start $ mysql -u root -p 

Now you should be able to login as root with your new password.

It is also possible to find the query that reset the password in /home/$USER/.mysql_history or /root/.mysql_history of the user who reset the password, but the above will always work.

Note: prior to MySQL 5.7 the column was called password instead of authentication_string. Replace the line above with

mysql> update user set password=PASSWORD("YOUR-NEW-ROOT-PASSWORD") where User='root'; 
like image 186
Benjamin Manns Avatar answered Oct 11 '22 11:10

Benjamin Manns