Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0

MySQL 5.7 version:

Method 1: Use the SET PASSWORD command

Format: mysql> set password for username@localhost = password('new password');

Example:mysql> set password for root@localhost = password('123');

mysql5.7 and mysql8.0 and above can be used

Method 2: Using mysqladmin

Format: mysqladmin -u username -p password new password

Example: mysqladmin -uroot -p password 123

MySQL version 5.7

Method 3: Use UPDATE to edit the user table directly

mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
mysql> flush privileges;

MySQL 5.7 and MySQL 8.0 and above

Method 4: Use alter. There is a pitfall in using this method. Many blogs say that you can use the following method to modify it, but it has not been successful:

alter user 'root'@'localhost' IDENTIFIED BY 'liuhehe';

Error:

ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'

Later, I checked the record of user='root' in the user table and found that the value of the host column was '%'. I modified the above SQL to

mysql> alter user 'root'@'%' IDENTIFIED BY 'liuhehe';
Query OK, 0 rows affected (0.03 sec)

Execution successful! !

The following method is only used for MySQL 5.7 version

Method 4: When you forget the root password

Take Windows as an example:

1. Shut down the running MySQL service.

2. Open a DOS window and go to the mysql\bin directory.

3. Enter mysqld --skip-grant-tables and press Enter. --skip-grant-tables means skipping the permission table authentication when starting the MySQL service.

4. Open another DOS window (because the previous DOS window cannot be moved) and go to the mysql\bin directory.

5. Type mysql and press Enter. If successful, the MySQL prompt > will appear.

6. Connect to the privilege database: use mysql; .

6. Change the password: update user set password=password("123") where user="root"; (don't forget to add a semicolon at the end).

7. Refresh privileges (required step): flush privileges; .

8. Exit quit.

9. Log out of the system, log back in, and log in using the username root and the new password 123 you just set.

Note: There is no password field in the MySQL database under version 5.7. The password field has been changed to

authentication_string.

Summarize

The above is a summary of the method of changing the root password in MySQL 5.7 and MySQL 8.0. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Detailed explanation of the idea of ​​installing mysql8.0.11 and changing the root password and connecting navicat for mysql
  • How to correctly modify the ROOT password in MySql8.0 and above versions
  • Solve the problem of changing the password when logging in for the first time after installing MySQL 8.0
  • MySQL 8.0.19 winx64 installation tutorial and change the initial password under Windows 10
  • MySQL 8.0.12 installation configuration method and password change
  • MySQL 8.0.15 installation and configuration graphic tutorial and password change under Linux
  • How to modify the root user password in mysql 8.0.16 winx64 and Linux
  • Problems with changing password and connecting to Navicat when installing and using MySQL 8.0.16 under Windows 7
  • mysql8.0 forgotten password modification and net command service name invalid problem
  • The correct way to change the password in MySQL 8.0

<<:  Vue implements dynamic query rule generation component

>>:  Upgrade Docker version of MySQL 5.7 to MySQL 8.0.13, data migration

Recommend

Solve the problem that ifconfig and addr cannot see the IP address in Linux

1. Install the Linux system on the virtual machin...

Instructions for using JSON operation functions in Mysql5.7

Preface JSON is a lightweight data exchange forma...

Use overflow: hidden to disable page scrollbars

Copy code The code is as follows: html { overflow...

How to use binlog for data recovery in MySQL

Preface Recently, a data was operated incorrectly...

Solution to Element-ui upload file upload restriction

question Adding the type of uploaded file in acce...

JavaScript Array Detailed Summary

Table of contents 1. Array Induction 1. Split a s...

Pricing table implemented with CSS3

Result: Implementation Code html <div id="...

Vue event's $event parameter = event value case

template <el-table :data="dataList"&...

Write a formal blog using XHTML CSS

The full name of Blog should be Web log, which mea...

MAC+PyCharm+Flask+Vue.js build system

Table of contents Configure node.js+nvm+npm npm s...

Practical method of deleting files from Linux command line

rm Command The rm command is a command that most ...

How to convert JavaScript array into tree structure

1. Demand The backend provides such data for the ...

Example code for implementing background transparency and opaque text with CSS3

Recently, I encountered a requirement to display ...