Posted over 5 years ago. Visible to the public.

Reset mysql root password

Stop the MySQL Server.

Copy
sudo /etc/init.d/mysql stop

Start the mysqld configuration.

Copy
sudo mysqld --skip-grant-tables &

Login to MySQL as root.

Copy
mysql -u root mysql

Replace YOURNEWPASSWORD with your new password or set it to an empty string (Password=PASSWORD('')) if you don't want to set a password.

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

Solve problems with connection errors

  • If you have the error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  • If you have the error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Login into the mysql database with the debian-sys-maint user (you find the password in /etc/mysql/debian.cnf)

Copy
sudo service mysql start mysql -u debian-sys-maint -p

Replace YOURNEWPASSWORD with your new password!

Copy
UPDATE mysql.user set Password=PASSWORD('YOURNEWPASSWORD') where User='root'; FLUSH PRIVILEGES; quit;

Solve problems with schema errors

  • If you have the error ERROR 1054 (42S22): Unknown column 'Password' in 'field list'

Replace YOURNEWPASSWORD with your new password!

Copy
UPDATE mysql.user set authentication_string=PASSWORD('YOURNEWPASSWORD') where User='root'; FLUSH PRIVILEGES; quit;

Solve problems with correct passwort

  • If you enter the correct password (after reset) and get a ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Set the password again:

Copy
sudo mysql GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'YOURNEWPASSWORD'; FLUSH PRIVILEGES;

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Author of this card:

Avatar
Martin Straub
Last edit:
17 days ago
by Emanuel De
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Martin Straub to makandra dev