Modify MySQL root password method in Linux

Source: Internet
Author: User

Method uses the Reset script

The code is as follows Copy Code

wget Http://xxxx/lnmp/ext/reset_mysql_root_password.sh;sh reset_mysql_root_password.sh

Suitable for LNMP or MySQL admin scripts in/etc/init.d/mysql and MySQL installed in/usr/local/mysql/. Otherwise, you will need to modify the script before performing the SH reset_mysql_root_password.sh.

Using 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 quotes behind the password are not required, but quotation marks are required if the password contains spaces or some special symbols.

Using 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 ');

Update the user table with the UPDATE statement reset 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;

Manual modification

1. Stop MySQL Service
Execution:/etc/init.d/mysql stop, not necessarily on your machine/etc/init.d/mysql may also be/etc/init.d/mysqld
2, skip verification to start MySQL
/usr/local/mysql/bin/mysqld_safe--skip-grant-tables >/dev/null 2>&1 &

Note: If the location of the Mysqld_safe is not the same as the above need to be modified to your, if not clear can be found with the Find command.

3. Reset Password
Wait a minute and then execute:/usr/local/mysql/bin/mysql-u root MySQL

When the MySQL prompt appears, enter: Update user Set password = password (' Password to set ') where user = ' root ';

After carriage return carries out: flush privileges; Refresh the MySQL system permissions related tables.  Re-execution: exit; Exit.

4, restart MySQL
Kill MySQL Process: Killall mysqld

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

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.