CentOS7 reset MySQL8.0 password

CentOS7 reset MySQL 8.0 password#

In the previous article, we have finished the installation of MySQL, the next part of this article will show how to reset the password.

  1. View the automatically generated password

After the installation is complete, MySQL will automatically generate a random password for us

The view command is as follows:

grep 'temporary password'/var/log/mysqld.log

Because the automatically generated password cannot be used directly and is not easy for us to remember, we need to change the password.

  1. Configuration file MySQL password-free login

Edit MySQL configuration file

vim /etc/my.cnf

Add the following sentence in the following line at the beginning of pid

skip-grant-tables

Save and exit.

  1. Restart MySQL service
service mysqld restart 
  1. Password-free login to MySQL
mysql -u root -p

When prompted to enter the password, hit enter directly.

  1. Choose mysql database
use mysql;

Because a user table of MySQL users is stored in the mysql database

  1. View the relevant information of the current root user in the user table of the mysql database
select host, user, authentication_string, plugin from user;

After executing the above command, a table will be displayed

The following information is in the form:

host: the ip'location' that allows the user to log in% means that it can be remote;

user: the user name of the current database;

authentication_string: user password (password field and password() function are discarded after mysql 5.7.9);

plugin: Password encryption method;

  1. Leave the default root password blank
use mysql;  
update user set authentication_string='' where user='root';
  1. Exit the mysql command line
quit
  1. Delete the skip-grant-tables at the end of the /etc/my.cnf file
vim /etc/my.cnf

Delete skip-grant-tables and save and exit.

  1. Restart MySQL service
service mysqld restart 
  1. Log in to MySQL again
mysql -u root -p

When prompted to enter the password, hit enter, because we have set the password to be blank just now.

  1. Use ALTER to change root user password
ALTER user 'root'@'localhost' IDENTIFIED BY 'Xpf123@';

Xpf123@ is the new password you set. Note that if this password is set relatively simple, such as 123456, etc., it will be unsuccessful. It will prompt you that the password is too simple. It is best to set it to uppercase letters, numbers, and symbols. combination.

After the execution, you will be prompted with OK, it means that the modification is successful. So far, resetting the password is complete. You can use the newly set password to log in and try.

Many students may have encountered many problems in changing the password. For example, if you installed MySQL 8.0 and then reset the password, or used the old command to change the password, an error was reported because the user table was discarded after MySQL 5.7.6 Password field and password() method, so using the old method to reset the password will not work for mysql 8.0!

Okay, that's all for today's explanation.

If you have any questions, please leave a message below!

For more technical articles, please pay attention to my official account:

Recommended Posts

CentOS7 reset MySQL8.0 password
CentOS 7 Root user password reset
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
CentOS install mysql
CentOS7 install mysql
CentOS 7 install MySQL 5.6
CentOS8 install MySQL8.0
CentOS7 install mysql8
CentOS7 install MySQL8
Centos MySQL8 configuration
centos 7.5 install mysql5.7.17
CentOS6.5 offline install MySQL5.6.26
Install MySQL5.7 in centos7
Install mysql5.7 under CentOS7
Centos7 install Mysql8 tutorial
Mysql8.0.15 installation configuration (centos7)
Centos manually install mysql8
Install mysql under Centos 7
Centos7 install Mysql database
Install mysql5.1 under CentOS6.5
Install mysql online on centos
Centos mysql installation and configuration
centos install mysql through yum
Install MySQL 8.0.16 on Linux Centos
CentOS 6.x installation mysql5.7 record
Install MySQL under Linux (CentOS 7)
Root password cracking under CentOS 7
CentOS mysql configuration master-slave replication
Centos6 install mysql 5.7.x series
CentOS8 install MySQL8 (pro test)
How to install MySQL on CentOS 8
CentOS7 yum install and start mysql
CentOS Yum compile and install MySQL 5.6
Install MySql with Docker in CentOS7
Performance comparison of MySQL centos 6 vs 7
Install MySQL on Linux CentOS7 (Windows)
CentOS7 yum install and start mysql
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos yum install mysql5.6 or above
Ubuntu install MySQL password initialization problem
CentOS 8 (1)
centos7 .*tar package to install MySQL5.7
The latest Centos7 installation Mysql8 guide
Centos7 mysql database installation and configuration
[Switch] CentOS7 64-bit installation mysql tutorial
Installation and use of Mysql under CentOS
CentOS yum install Apache + PHP + Tomcat7 + MySQL
MySQL 8.0 installation, deployment and configuration under CentOS 6/7
CentOS7.5 source code compile and install mysql5.7.29
Install mysql8.0.13 version under Linux CentOS7 system
Linux environment construction: CentOs + Apache + MySQL + PHP
Centos7 compile and install MySQL8 problem record
CentOS container installation in Docker uses MySQL
Detailed tutorial on installing MySQL 8 in CentOS 7
CentOS7.4 source code compile and install MySQL8.0
How to change MySQL password under Ubuntu
Novice learning Linux (eight) ---- MySql installation (Centos7)
CentOS7 system yum way to install MySQL5.7