How to reset MySQL 'root password.
Step 1 .
Stop MySQL database using the following command
# service mysqld stop
Stopping mysqld: [ OK ]
# mysqld_safe --skip-grant-tables --skip-networking &
[1] 8291
130708 19:28:13 mysqld_safe Logging to '/var/log/mysqld.log'.
130708 19:28:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Step 3:
Connect to MySQL and reset the root password as shown below.
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> UPDATE mysql.user SET Password=PASSWORD('newrootpassowrd') WHERE User='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
Step 4:
Restart mysql service
$service mysqld restart
Stop MySQL database using the following command
# service mysqld stop
Stopping mysqld: [ OK ]
Step 2:
Restart mysqld with
--skip-grant-tables
and --skip-networking
option. This enables anyone to connect to mysql without a password and with all privileges. Because this is insecure --skip-networking
should be used
in conjunction to prevent remote clients from connecting.
This is shown below:
[1] 8291
130708 19:28:13 mysqld_safe Logging to '/var/log/mysqld.log'.
130708 19:28:13 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Step 3:
Connect to MySQL and reset the root password as shown below.
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> UPDATE mysql.user SET Password=PASSWORD('newrootpassowrd') WHERE User='root';
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
Step 4:
Restart mysql service
$service mysqld restart
Comments