Skip to content

Instantly share code, notes, and snippets.

@ValentinNikolaev
Last active January 24, 2021 17:55
Show Gist options
  • Select an option

  • Save ValentinNikolaev/ffaf6d168dd936667ab04d85b6075fff to your computer and use it in GitHub Desktop.

Select an option

Save ValentinNikolaev/ffaf6d168dd936667ab04d85b6075fff to your computer and use it in GitHub Desktop.
Reset root mysql password Ubuntu
sudo /etc/init.d/mysql stop
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
Start the mysql client process using this command
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');
If you have a mysql root account that can connect from everywhere, you should also do:
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
Alternate Method:
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = 'localhost' AND User = 'root';
And if you have a root account that can access from everywhere:
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = '%' AND User = 'root';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment