Find us on facebook

Jun 2, 2015

Change MYSQL Root Password

Do not confuse server root user with the MySQL root user.

Server's main user is server root. The MySQL root(admin) user has complete control over MySQL only.
This two 'root' users are not connected.

Stop MySQL

Ubuntu or Debian:
sudo /etc/init.d/mysql stop

For CentOS, Fedora, and RHEL:
sudo /etc/init.d/mysqld stop

Safe mode
Next we need to start MySQL in safe mode - start MySQL but skip the user privileges table.

sudo mysqld_safe --skip-grant-tables &
The ampersand (&) at the end of the command is required.

Login
Log into MySQL and set the password.

mysql -u root
when we started MySQL we skipped the user privileges table.So no password needed.

Next, instruct MySQL which database to use:

use mysql;(Where all details kept)(in mysql db there is user table. All users stored there with passwords.
We are going to change That user's table's root user's password. If there is no user called root in this table,
We need to get main user from this table. once my main user was admin. So instead "root" I had to use "admin")

Reset Password

Enter the new password for the root user as follows:
update user set password=PASSWORD("mynewpassword") where User='root'; //where User='admin'

Flush the privileges:
flush privileges;

Restart
Now the password has been reset, we need to restart MySQL by logging out:
quit

Stop and Star MySQL.

Ubuntu and Debian:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

CentOS and Fedora and RHEL:
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start

Login
Again login and test password:
mysql -u root -p // mysql -u admin -p

No comments:

Post a Comment