Shell resets the password for the new MySQL version

Source: Internet
Author: User

Shell resets the password for the new MySQL version
After the old version of MySQL is installed successfully, the root account has no password, which is convenient but insecure. From version 5.6.8 (the latest version is 5.6.20), a random temporary password is automatically set during the installation of MySQL installed in RPM mode. After the installation is complete, find the password in the temporary file $ HOME/. mysql_secret under the account. Its content is as follows:

# The random password set for the root user at xxxxxxxxxxxxxxxx: eQLxneugXwlucXLk

This password is a temporary password, which can only be used after Logon: change the password. After logging on to the MySQL client, run the following command:

Set password = password ('20140901 ');

Then, log out with the new password (123456) and log on again.

Quit;

This is a bit safer, but there is a problem, so that the installation process cannot be automated through SHELL scripts. I tried two methods:

1. Run the mysqladmin command To change the password. If you fail To change the password, the following error occurs: Your password has expired. To log in you must change it using a client that supports expired passwords.

It seems that the random temporary password cannot be used for mysqladmin

2. Run the mysql command to change the password.

Echo "set password = password ('000000')" | mysql-pzvhhvTKlJLSAdkGP

The error message is the same as that of the mysqladmin command.

It seems that this restriction is very strict. I have come up with a method to solve the problem:

1. Stop MySQL

Service mysql stop

2. Clear the MySQL database directory (if any useful data exists, back up it on your own)

\ Rm-rf/var/lib/mysql /*

3. reinitialize the database. The -- random-passwords parameter is automatically added during RPM initialization. No parameters are required for this re-execution.

Mysql_install_db

4. Modify the user/group to which the generated file belongs.

Chown-R mysql: mysql/var/lib/mysql/

5. Start MySQL

Service mysql start

6. Set a new password

/Usr/bin/mysqladmin password 123456

If it succeeds, you have successfully set the password to 123456. Of course, you can set it more complex. Because the above steps are shell commands, You can automatically set the password in the new MySQL version. Set new password

/Usr/bin/mysqladmin password 123456

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.