Linux forgot MySQL database password

Source: Internet
Author: User

I installed on the CentOS6.4 after the MySQL, unable to enter through the root, because the installation, and did not set the root password, seems to have an initial random password, but do not remember, too troublesome, directly reset the root password.

After installing MySQL using the RPM package, follow the steps to reset the root password:

Start MySQL:
#/etc/init.d/mysql start


After successful startup, view the MySQL process information and getMysqld_safeThe installation directory (very critical)
#ps-ef | Grep-i MySQL
Root 3466 1 0 01:45 pts/1 00:00:00/bin/sh/usr/bin/mysqld_safe--datadir=/var/lib/mysql--pid-file=/var/lib/ MYSQL/BSC. Test.pid
MySQL 3569 3466 01:45 pts/1 00:00:00/usr/sbin/mysqld--basedir=/usr--datadir=/var/lib/mysql--plugin-dir=/usr /lib64/mysql/plugin--user=mysql--log-error=/var/lib/mysql/bsc. Test.err--PID-FILE=/VAR/LIB/MYSQL/BSC. Test.pid
Root 3597 3105 0 01:45 pts/1 00:00:00 grep-i MySQL

You can see where the Mysqld_safe is installed (the blue section above):/usr/bin/
Then execute the command to stop MySQL:
/etc/init.d/mysql stop

To start MySQL in a safe manner:
#/usr/bin/mysqld_safe--skip-grant-tables >/dev/null 2>&1 &

Wait for 5 seconds, and then execute the following statement:
#/usr/bin/mysql-u Root MySQL
Note: MySQL is the same as the Mysql_safe directory:/usr/bin/, this is through the "Ps-ef | grep-i MySQL "command to get.

When the "mysql>" prompt appears, enter:
mysql> Update user Set password = password (' root ') where user = ' root ';
Enter after the execution (refresh the MySQL system permissions related tables):
mysql> flush Privileges;
Then execute exit exit:
Mysql> exit;

After exiting, use the following command to log in to MySQL and try to succeed:

#mysql-U root-p

Enter password as prompted: root

But execute the View database command error:

mysql> show databases;
ERROR 1820 (HY000): Must SET PASSWORD before executing this statement

Workaround:

Mysql> SET password=password (' root ');
Query OK, 0 rows Affected (0.00 sec)

Mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Performance_schema |
| Test |
+--------------------+
4 rows in Set (0.00 sec)

Linux forgot MySQL database password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.