How to Reset Root Password in MySQL 8.0
If you forget the MySQL root password on MySQL 8.0 server, you can follow the instruction here to reset the root user password.
First, stop the MySQL server if it is already running
1 |
systemctl stop mysql |
Create folder
1 2 |
mkdir /var/run/mysqld/ chown mysql:mysql /var/run/mysqld/ |
Now start MySQL with –skip-grant-tables option
1 |
mysqld --skip-grant-tables --user=mysql |
Take a new terminal, connect to MySQL
1 |
mysql -u root -p |
When it asks for the root password, just press enter. No need to enter any password. To reset MySQL root password, run
1 2 |
FLUSH PRIVILEGES; ALTER USER 'root'@'localhost' IDENTIFIED BY 'MySQL_NEW_ROOT_PW_HERE'; |
After running the above 2 SQL commands, exit MySQL command prompt with command exit or press CTRL+D.
Now you need to find the process ID of MySQL
1 |
ps aux | grep mysql |
Kill the process with
1 |
kill -9 PROCESS_ID_OF_MYSQLD |
Now start MySQL normally with
1 |
systemctl start mysql |
Now you will be able to login to the MySQL server using the new PASSWORD
1 |
mysql -u root -p |
See MySQL root password, MySQL Could not create unix socket lock file