MySQL database root account password forgotten two processing methods (valid)

Source: Internet
Author: User
Tags pkill

Method 1:


1. Stop the MySQL service

# Kill ' Cat/var/run/mysqld/mysqld.pid '

Or

# Pkill Mysqld

2. Create a text file for a password assignment statement

# VI Mysql-init

ALTER USER ' root ' @ ' localhost ' identifiedby ' mynewpass!6 ';

Resets the password before loading the authorization table.

3. Start the MySQL service using the-init-file option

# mysqld--init-file=mysql-init--user=mysql &

4. Delete the text file and connect to MySQL using the new password

# rm-f Mysql-init

# mysql-uroot-p ' mynewpass!6 '

5. Stop the MySQL service and start normally

# Kill ' Cat/var/run/mysqld/mysqld.pid '

# Systemctl Start mysqld


Method 2:


1. Stop the MySQL service

# Kill ' Cat/var/run/mysqld/mysqld.pid '

# Pkill Mysqld

2. Start the MySQL service using the--skip-grant-tables--skip-networking option

# mysqld--skip-grant-tables--skip-networking--user=mysql

--skip-grant-tables: Skip Authorization Form authentication

--skip-networking: With the Skip authorization table option, all people can log in without a password, which is very insecure, this option does not listen to the network and prevents malicious logons.

3. No password connection to MySQL

# MySQL

4. Reset Password

mysql> FLUSH privileges;

Mysql> ALTER USER ' root ' @ ' localhost ' identified by ' mynewpass!6 ';

5. Stop the MySQL service and start normally

# Kill ' Cat/var/run/mysqld/mysqld.pid '

# Systemctl Startmysqld


Simple, fast, effective, remember the collection Oh! In case the root password can not be found any day!


This article is from the "Li Zhenliang Technology Blog" blog, make sure to keep this source http://lizhenliang.blog.51cto.com/7876557/1977881

MySQL database root account password forgotten two processing methods (valid)

Related Article

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.