After installing MySQL, unable to enter through the root, because the installation, and did not set the root password, there seems to be an initial random password, but do not remember, too troublesome, directly reset the root password.
After installing MySQL with 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 get the Mysqld_safe 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 the installation location of the Mysqld_safe (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 5 seconds, and then execute the following statement:
#/usr/bin/mysql-u Root MySQL
Note: MySQL, like the Mysql_safe directory, is:/usr/bin/, this is through "ps-ef | grep-i MySQL "command to get.
When you receive the mysql> prompt, enter:
mysql> Update user Set password = password (' root ') where user = ' root ';
Perform (refresh MySQL system permissions related tables) after carriage return:
mysql> flush Privileges;
Then execute exit exit:
Mysql> exit;
After exiting, use the following command to login to MySQL and try to succeed:
#mysql-U root-p
Enter password by prompt: root