After installing mysql on CentOS 6.4, I cannot access it through root. Because the root password is not set during installation, it seems that there is an initial random password, but I do not remember it, too troublesome. Reset the root password directly.
After installing mysql using the rpm package, follow these steps to reset the root password:
Start mysql:
#/Etc/init. d/mysql start
Check the mysql process information and obtain the installation directory of mysqld_safe (critical ):
# Ps-ef | grep-I mysql
Root 3466 1 0 00:00:00 pts/1/bin/sh/usr/bin/mysqld_safe -- datadir =/var/lib/mysql -- pid-file =/var/lib/mysql/ BSC. TEST. pid
Mysql 3569 3466 16 00:00:00 pts/1/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 00:00:00 pts/1 grep-I mysql
You can see the installation location of mysqld_safe (the blue part above):/usr/bin/
Run the following command to stop mysql:
/Etc/init. d/mysql stop
Start mysql in a safe way:
#/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: The mysql and mysql_safe directories are the same:/usr/bin/, which is obtained through the "ps-ef | grep-I mysql" command.
Enter:
Mysql> update user set password = Password ('root') where User = 'root ';
Press enter and execute (refresh the table related to MySQL system permissions ):
Mysql> flush privileges;
Then execute exit to exit:
Mysql> exit;
After exiting, run the following command to log on to mysql and check whether it is successful:
# Mysql-u root-p
Enter the password as prompted: root