It is possible to reset the root password. Use the following procedure for resetting the password for any MySQL root accounts on Unix / Linux / BSD like operating systems.
You need to login as root user under UNIX / Linux.
Step # 1: Stop MySQL
Type the following command to stop mysql server under RHEL / Fedora / CentOS Linux:# /etc/init.d/mysqld stopUse the following command if you are using FreeBSD:
# /usr/local/etc/rc.d/mysql-server stopUse the following command if you are using Debian / Ubuntu Linux:
# /etc/init.d/mysql stopAlternatively, you can stop the MySQL server by sending a kill to the mysqld process, using the path name of the .pid file in the following bash specific command:
# kill $(cat /var/run/mysqld/mysqld.pid)OR
# pgrep -u mysql mysqld
# kill PIDOr, simply use killall command under Linux:
# killall mysqlStep # 2: Create new mysql password sql script
Create a sql file called /root/mysql.reset.sql as follows (replace YOUR-NEW-MYSQL-PASSWORD with actual new password you would like to use):# vi /root/mysql.reset.sqlAppend the following code:
UPDATE mysql.user SET Password=PASSWORD('YOUR-NEW-MYSQL-PASSWORD') WHERE User='root';Save and close the file.
FLUSH PRIVILEGES;
Step # 3: Set new mysql root password
Type the following command:# mysqld_safe --init-file=/root/mysql.reset.sql &Sample output:
nohup: ignoring input and redirecting stderr to stdoutAnd you are done with resetting operation. Simply, stop server and start again:
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[20970]: started
# killall mysqld
# /etc/init.d/mysql start
No comments:
Post a Comment