After installing mysql in CentOS6, reset the root password to CentOS6CentOS.
BitsCN.com
After installing mysql on CentOS6.4, I cannot enter through root because the root password is not set during installation. it seems that I have an initial random password, but I don't remember it. it is 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
View mysql process information and obtainMysqld_safeInstallation directory (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
BitsCN.com