Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset mysql root password?

I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts. Since it is impossible to connect without the error:

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

I have search a little on the net before, and even the technic:

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

does not work, or I didn't understood how it worked.

I'm on FreeBSD 8.1, my version of PhpMyadmin is 2.11.

Thank you in advance for your answers.

like image 555
4m0ni4c Avatar asked Nov 23 '10 16:11

4m0ni4c


People also ask

What if I forgot the root password of 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 change the root password in MySQL?

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.

How do I reset my root password?

Enter the following: mount -o remount rw /sysroot and then hit ENTER. Now type chroot /sysroot and hit enter. This will change you into the sysroot (/) directory, and make that your path for executing commands. Now you can simply change the password for root using the passwd command.


1 Answers

I summarised my solution here: http://snippets.dzone.com/posts/show/13267

sudo stop mysql
sudo mysqld --skip-grant-tables --skip-networking

mysql
mysql> update mysql.user set password = password('your_new_password') where user = 'root';
mysql> flush privileges;
mysql> exit;
sudo mysqladmin shutdown
sudo start mysql
like image 168
Alexey Avatar answered Oct 08 '22 07:10

Alexey