How to change the root password of MySQL in CentOS environment: centosmysql

Source: Internet
Author: User

How to change the root password of MySQL in CentOS environment: centosmysql

Environment related:
OS: CentOS release 6.9
IP: 192.168.1.10
MySQL: MariaDB-10.1.30

1. confirmation before modification

To change the root password, restart the mysql database to ensure that the mysql database can be restarted during production;

Check whether the root user is directly used in production to connect to the database. If yes, make associated changes;

Before changing the password, stop the application that connects to the database, that is, stop all production lines related to the database.

2. Stop the database and change the password

Ps-ef | grep mysql | grep-v grep # Find the corresponding mysql server daemon, check whether other mysql service daemon has ps-ef | grep mysql | grep-v grep | xargs kill-9 # kill the command process of the root startup database and the daemon process of the database, otherwise, the database will automatically start again # Kill the process and stop the database. Before killing the process, make sure all applications connected to the database are stopped !!! Mysqld_safe -- user = mariadb -- skip-grant-tables & # ignore the authorization table to start the database. If the password is used, the database cannot be logged in. # If the application connected to the database is not stopped, in this case, mysqluse mysql of the database cannot be successfully connected; select Host, User, Password from user where user = 'root'; exit; # enter the mysql database, query the password of the current root password and save it for rollback # For example, if my current password is vincent and the password is '* CDA83EBFF468E905FF304FE0D3D9F4D665C6579D' mysqluse mysql; update user set password = password ('test') where user = 'root'; exit; # enter the mysql database and set the root password mysqladmin shutdownmysqld_safe -- user = mariadb & # restart the database, login test mysql-uroot-ptest-Dmysqlexit; # login successful

3. Operation rollback

After you modify the root password, you will find many problems. For example, if an unknown application connects to the database with the original root password (a legacy problem with the egg history), you need to roll back.

Mysql-uroot-ptest-Dmysqlupdate user set password = '* CDA83EBFF468E905FF304FE0D3D9F4D665C6579D' where user = 'root'; flush privileges; exit; # Roll Back mysql-uroot-pvincent-Dmysqlexit using the password before the root password recorded in the previous step; # The rollback is complete.

4. Related Knowledge points

You can directly use the password to set the password. Currently, you cannot find a way to directly convert the password to plaintext. You can use the password function to view the password value:

mysql -uroot -pvincentselect password('vincent'),password('test');

However, if you know the password, you can use the root permission to change the password of a user, use it, and restore it.
This situation is often used when a user's password is forgotten and the password is reset. The same situation occurs in the oracle database.

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.