Forcefully reset MySQL password [CentOS]
Sometime you need to reset MySQL password on a server you have root access to. Here’s a step-by-step how-to to accomplish this task on a CentOS 6 server.
Stop the MySQL daemon process
[root@memento ~]# /etc/init.d/mysqld stop
Start the mysqld daemon process with the –skip-grant-tables option.
[root@memento ~]# mysqld_safe --skip-grant-tables &
Now you should connect to MySQL without password:
[root@memento ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.95 Source distribution
Copyright (c) 2000, 2011, 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>
Now you can set new password for user root as follows:
mysql> UPDATE mysql.user SET Password=PASSWORD('***YOUR NEW PASSWORD HERE***') WHERE User='root';
At this point, you may exit the MySQL prompt (using the ‘quit’ or ‘exit’ command), then you can restart the MySQL daemon in normal mode as follows:
[root@memento ~]# /etc/init.d/mysqld restart
Now you can to connect to MySQL with the new password:
[root@memento ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is ...
Read other posts