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

Sample code for CSS image animation effects (photo frame)

This article introduces the sample code of CSS pi...

Implementing circular scrolling list function based on Vue

Note: You need to give the parent container a hei...

CentOS 8 Installation Guide for Zabbix 4.4

Zabbix server environment platform ZABBIX version...

CSS to implement QQ browser functions

Code Knowledge Points 1. Combine fullpage.js to a...

How to quickly clean up billions of data in MySQL database

Today I received a disk alarm exception. The 50G ...

HTML+CSS to create a top navigation bar menu

Navigation bar creation: Technical requirements: ...

25 Tools to Improve Website Usability and Conversion Rates

For a website, usability refers to whether users c...

JS asynchronous execution principle and callback details

1. JS asynchronous execution principle We know th...

How to safely shut down a MySQL instance

This article analyzes the process of shutting dow...

Detailed tutorial on installing JDK1.8 on Linux

1. Cleaning before installation rpm -qa | grep jd...

CSS shadow animation optimization tips

This technique comes from this article - How to a...

Installation and use tutorial of Elasticsearch tool cerebro

Cerebro is an evolution of the Elasticsearch Kopf...

Website User Experience Design (UE)

I just saw a post titled "Flow Theory and Des...

Summary of things to pay attention to in the footer of a web page

Lots of links You’ve no doubt seen a lot of sites ...

Detailed explanation of webpage screenshot function in Vue

Recently, there is a requirement for uploading pi...