Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resetting MySQL root password when current password is not known

Tags:

I have inherited a server that has mysql installed on it. I don't have the mysql password for any user, not even root (although I have the linux root password). Plus, I am only aware of one other user account besdies root, and that one does not have privileges to perform any action, not even SELECT.

I tried stopping the mysql servicw, restarting with the skip grant tables option, and just logging in without password:

service mysqld stop service mysqld start --skip-grant-tables & mysql -u root 

But get the following error:

Access denied for user 'root'@'localhost' (using password: NO) 

I then tried resetting the password:

mysqladmin -u root password 'newpw' 

But that also gives an access denied error.

I also tried logging in as the other user (without pw) and executing the following command:

UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; 

and got this error:

ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user' 

I have also tried removing mysql and reinstalling, but I get the same errors.

Any suggestions?

like image 672
Bad Programmer Avatar asked Apr 26 '12 17:04

Bad Programmer


People also ask

How do I find my current MySQL root 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.

What is the process for resetting the MySQL root password in case the password is lost or forgotten?

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 change the root password in MySQL?

Configuring a default root password for MySQL/MariaDB 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

try sudo dpkg-reconfigure mysql-server-5.5 and you will be asked for the new root password.

Replace 5.5 with your current mysql-server version

like image 89
Amadu Bah Avatar answered Oct 05 '22 22:10

Amadu Bah