Skip to content

Instantly share code, notes, and snippets.

@EngKhaledB
Last active February 20, 2019 11:36
Show Gist options
  • Save EngKhaledB/a65110d851e7dfcd174816b9d958bc87 to your computer and use it in GitHub Desktop.
Save EngKhaledB/a65110d851e7dfcd174816b9d958bc87 to your computer and use it in GitHub Desktop.
Reset MySQL root Password

How to Reset MySQL Root Password?

Stop the mysql demon process using this command :

sudo /etc/init.d/mysql stop

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

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

Start the mysql client process using this command & Update the password:

mysql -u root
FLUSH PRIVILEGES;
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
FLUSH PRIVILEGES;
exit;

Restar MySQL

sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

In case, MySQL did not started, We need to kill the current running proccesses:

Show mysql running proccesses:

ps -A | grep mysql

Output:

28382 pts/0    00:00:00 mysqld
28635 ?        00:00:00 mysqld

Kill the proccesses:

sudo kill -SIGKILL 28382
sudo kill -SIGKILL 28635

Start MySQL Proccess:

sudo /etc/init.d/mysql start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment