Skip to content

Instantly share code, notes, and snippets.

@anilnabin25
Forked from poudelmadhav/reset_mysql_password.md
Created October 31, 2022 06:46
Show Gist options
  • Save anilnabin25/eeae88f635d0c4c6b7b74b288c736372 to your computer and use it in GitHub Desktop.
Save anilnabin25/eeae88f635d0c4c6b7b74b288c736372 to your computer and use it in GitHub Desktop.
Reset mysql root password

Reset MySQL Root Password:

  • Stop MySQL
sudo service mysql stop
  • Make MySQL service directory.
sudo mkdir /var/run/mysqld
  • Give MySQL user permission to write to the service directory.
sudo chown mysql: /var/run/mysqld
  • Start MySQL manually, without permission checks or networking.
sudo mysqld_safe --skip-grant-tables --skip-networking &
  • Log in without a password.
mysql -uroot mysql
  • Update the password for the root user.
UPDATE mysql.user SET authentication_string=PASSWORD(''), plugin='mysql_native_password' WHERE User='root';
EXIT;
  • Turn off MySQL.
sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
  • Start the MySQL service normally.
sudo service mysql start
  • Login to MySQL with new password.
mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment