How To Reset A MySQL Root Password

0
42
How To Reset MySQL Root Password

MySQL contains it own ‘root’ password independent of the system root password, this is a guide on how to reset the MySQL root password. To reset it you will need root access on the server that has the MySQL instance. The same process applies to percona and mariadb servers as well, the only differences will be the stop and start commands (mariadb for mariadb)If you already know the root password,  you can also connect to directly to MySQL and reset the password that way. This can be used for resetting any users MySQL password as well.Connect to MySQL:mysql -uroot -pSelect the mysql database:use mysql;Update the root password:update user set password=PASSWORD(“newpass”) where User=”root”;Load the new privileges:flush privileges;Exit MySQL:quit;Thats it for resetting a user password in mysql.This covers how to reset the mysql root password if you do not know the current password.Stop MySQLFirst you will need to stop the mysql serviceOn CentOS 6:/etc/init.d/mysql stopOn Centos/RHEL 7:systemctl stop mysqlStart mysqld_safeYou will then want to run mysql_safe with the skip grant tables option to bypass passwords with MySQL:mysqld_safe –skip-grant-tables &Reset MySQL Root PasswordYou will now want to connect to MySQL as root:mysql -urootThen use the mysql database:use mysql;Set a new password:update user set password=PASSWORD(“newpass”) where User=”root”;You will want to replace newpass with the password you want to useFlush the privileges:flush privileges;Exist mysql:exit;Restart MySQLOn Centos 6:/etc/init.d/mysql restartOn Centos 7:systemctl restart mysqlTest New Root MySQL Password:mysql -u root -pYou should now be able to connect  successfully to mysql as root using the new password you set.Sep 4, 2017LinuxAdmin.io

LEAVE A REPLY

Please enter your comment!
Please enter your name here