Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to Reset MySQL root Password in Linux  (Read 1347 times)

0 Members and 1 Guest are viewing this topic.

akhilt

  • Guest
How to Reset MySQL root Password in Linux
« on: March 28, 2018, 08:41:42 am »
How to Reset MySQL root Password in Linux

MySQL is an open source database software widely used for data storage. Sometimes we forgot MySQL root password. So don’t be panic, This tutorial will help you to reset MySQL root password with simple steps.

Step 1 – Start MySQL in Safemode

First of all, you are required to stop running MySQL server.Use one of the following commands to stop MySQL server on your Linux system:

Code: [Select]
# service mysql stop              //For SysVinit based ystems
# systemctl stop mysql.service    //For Systemd based Systems

Now, start MySQL server in safe mode using the following command:

Code: [Select]
# mysqld_safe --skip-grant-tables &
In safe mode, MySQL does not prompt for login password.

Step 2 – Reset MySQL root Password

Now login to MySQL server as root user and change password using the following set of commands. This will reset MySQL root password on your system.

For MySQL 5.6 or Below
Code: [Select]
# mysql -u root

mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEW-PASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit

For MySQL 5.7 or Above
Code: [Select]
# mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD("NEW-PASSWORD");
mysql> FLUSH PRIVILEGES;
mysql> quit

Step 3 – Restart MySQL Server

After changing password stop the MySQL (running in safe mode) service and start it again with the commands below:

Code: [Select]
//For SysVinit based systems
# service mysql stop
# service mysql start

//For Systemd based systems
# systemctl stop mysql.service
# systemctl start mysql.service

Step 4 – Verify New Password

After resetting MySQL root account password and restarting, just verify new password by logging in.

Code: [Select]
[color=black][color=brown][size=14pt]# mysql -u root -p

Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.5.57 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other na# mysql -u root -p

Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.5.57 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>mes may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>[/size][/color][/color]