Skip to content

Instantly share code, notes, and snippets.

@abhijithvijayan
Last active January 8, 2020 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhijithvijayan/c2bc7e430c8ffafdc3743e6c28c75686 to your computer and use it in GitHub Desktop.
Save abhijithvijayan/c2bc7e430c8ffafdc3743e6c28c75686 to your computer and use it in GitHub Desktop.
Reset MySql Root Password

Use the following steps to reset a MySQL root password by using the command line interface.

Stop the MySQL service

(Ubuntu and Debian) Run the following command"

sudo /etc/init.d/mysql stop

(CentOS, Fedora, and Red Hat Enterprise Linux) Run the following command:

sudo /etc/init.d/mysqld stop

if mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists

sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld

Start MySQL without a password

Run the following command. The ampersand (&) at the end of the command is required.

sudo mysqld_safe --skip-grant-tables &

Connect to MySQL

Run the following command:

mysql -uroot

Set a new MySQL root password

Run the following command:

use mysql;
update user set authentication_string=PASSWORD("newPasswordHere") where User='root';
update user set plugin="mysql_native_password" where User='root';
flush privileges;
quit;

Login to MySql server using new password

mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment