MySQL ­ Restoring the root password

  • 59th day of Discord, in the yold 3177
  • 3 Comments

logo-mysqlA common problem with mysql databases is the loss of the root password for various reasons. This article will describe how to quickly recover a root password in mysql without losing data, using Debian/Ubuntu as an example.

Usually, when trying to run mysql, this problem is followed by a message:

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

or

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

To change the root password in mysql, log in to the root session in the console first:

su

Then stop the running mysql service running:

service mysql stop

After using this command:

mysqld_safe --skip-grant-tables &

you can login to mysql without a password:

mysql -uroot mysql

In the mysql session, enter the following lines:

UPDATE user SET password=PASSWORD("your_password") WHERE user="root";
FLUSH PRIVILEGES;
EXIT

Where instead of your_password – enter your new password.

After that you only need to run mysql:

/etc/init.d/mysql restart

  1. olegscorpion says:

    Спасибо, оказывается есть одно “НО” когда набираешь mysql -uroot mysql то появляется вот такая строчка: mysql> (это значит ты вошел) и вводиш после входа UPDATE user SET password=PASSWORD(“ХХХХХХХ”) WHERE user=”root”; то появляется вот что : -> и всё, на команды не реагирует постоянно появляется -> , даже выход EXIT не хочет срабатывать . Вообщем это просто был глюк системы . потом после некоторых перезагрузок все стало принимать нормально.

  2. Сергей says:

    спасибо друзья, помогли.

  3. Yuran says:

    update user set authentication_string=password(‘1111′) where user=’root’;

Leave a Comment to olegscorpion

Your email address will not be published. Required fields are marked *