How to reset the MySQL ROOT Password in Linux

Source: Internet
Author: User

I personally think that the methods for changing the mysql root Password are similar in both linux and windows systems. Next I will explain how to reset the MySQL ROOT Password in Linux, for more information, see.

Restart mysql root Password

Method 1: Use mysqladmin

The Code is as follows: Copy code

#./Mysqladmin-u root password 'newpassword'

#./Mysqladmin-u root-h host_name password 'newpassword'

Usually mysqladmin's path is/usr/bin, host_name is your real host name, e.g. localhost. localdomain.

The quotation marks behind the password are not mandatory. However, if the password contains spaces or special symbols, use quotation marks.

Method 2: Use the mysql set password command

The Code is as follows: Copy code

#./Mysql-u root

Mysql> set password for 'root' @ 'localhost' = PASSWORD ('newpassword ');

Mysql> set password for 'root' @ 'host _ name' = PASSWORD ('newpassword ');

Method 3: Use the UPDATE statement to UPDATE the user table and reset the ROOT password.

The Code is as follows: Copy code

#./Mysql-u root

Mysql> UPDATE mysql. user SET Password = PASSWORD ('newpassword') WHERE User = 'root ';

Mysql> flush privileges;

Method 4: Start MYSQL security mode and reset the ROOT password

1. Stop the MySQL process

Run:/etc/init. d/mysql stop, the specific location may vary with the system, or/etc/init. d/mysql,/etc/init. d/mysqld and other paths, or terminate directly below (it is best not to use the following forced statement ):

The Code is as follows: Copy code

# Killall-TERM mysqld

2. Start MySQL in Safe Mode

The Code is as follows: Copy code

# Mysqld_safe-skip-grant-tables &

Or,

# Mysqld_safe -- skip-grant-tables>/dev/null 2> & 1 &

Tip: mysqld_safe is generally in the/usr/local/mysql/bin/directory.

3. log on to MYSQL

After completing the above two steps, you can enter MySQL without a password.

The Code is as follows: Copy code

# Mysql-u root

Or,

#/Usr/local/mysql/bin/mysql-u root mysql

4. Change the ROOT password

Execute the following statements in sequence:

The Code is as follows: Copy code

Use mysql;

Select host, user, password from user;

Update user set password = password ("newpassword") where user = "root"

Flush privileges;

5. log out of the console and restart the MYSQL service.

The Code is as follows: Copy code

Service mysqld restart

Or,

/Etc/init. d/mysql restart

Forget the MySQL root Password


1. manually modify

1. Stop the MySQL Service

Run:/etc/init. d/mysql stop. It may be/etc/init. d/mysql or/etc/init. d/mysqld on your machine.

2. Skip verification to start MySQL

The Code is as follows: Copy code

/Usr/local/mysql/bin/mysqld_safe -- skip-grant-tables>/dev/null 2> & 1 &

Note: If the location of mysqld_safe is different from above, you need to change it to yours. If you are not clear about it, you can use the find command to find it.

3. Reset the password

Wait for a while and then run:/usr/local/mysql/bin/mysql-u root mysql

Enter: update user set password = Password ('password to set') where User = 'root' after the mysql prompt appears ';

Press enter and run: flush privileges; refresh the table related to MySQL system permissions. Run exit.

4. Restart MySQL

Killall mysqld

Restart MySQL:/etc/init. d/mysql start

Ii. Use the reset script

The Code is as follows: Copy code

The wget http://soft.vpser.net/lnmp/ext/reset_mysql_root_password.sh;sh reset_mysql_root_password.sh

Suitable for lnmp or MySQL management scripts in/etc/init. d/mysql and mysql installed in/usr/local/mysql. Otherwise, you need to modify the script before executing it.

The Code is as follows: Copy code

Sh reset_mysql_root_password.sh.

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.