After installing mysql in CentOS6, reset the root password _ MySQL

Source: Internet
Author: User
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

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.