Skip to content

Instantly share code, notes, and snippets.

@dubcl
Created October 17, 2018 17:29
Show Gist options
  • Save dubcl/0e5d0180fab05e3c1e426b2347a04515 to your computer and use it in GitHub Desktop.
Save dubcl/0e5d0180fab05e3c1e426b2347a04515 to your computer and use it in GitHub Desktop.
Reset lost mysql root password

Stop mysql

service mysql stop

Start the mysqld demon process using the --skip-grant-tables option with this command

/usr/sbin/mysqld --skip-grant-tables --skip-networking &

Connect as root without password

mysql -u root

From the mysql prompt execute this command to be able to change any password

FLUSH PRIVILEGES;

Then reset/update your password

SET PASSWORD FOR root@'localhost' = PASSWORD('password');

Or

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

Or

USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = 'localhost' AND User = 'root';

Or

USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = '%' AND User = 'root';

Do again

FLUSH PRIVILEGES;

Then stop the mysqld process and relaunch it with the classical way:

service mysql stop
service mysql start

Link https://help.ubuntu.com/community/MysqlPasswordReset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment