4 ways to modify MySQL root password (summary)

4 ways to modify MySQL root password (summary)

Method 1: Use the SET PASSWORD command

First log in to MySQL.

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

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

Method 2: Using mysqladmin

Format: mysqladmin -u username -p old password password new password

Example: mysqladmin -uroot -p123456 password 123

Method 3: Use UPDATE to edit the user table directly

First log in to MySQL.

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

Method 4: When you forget the root password, you can do this

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.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • MySQL - 4 ways to change the root password (taking Windows as an example)
  • What should I do if I forget my MySQL password? How to reset MySQL root password
  • Solution to forgetting the root password of mysql under windows
  • How to view or modify the root password of MySQL if it is forgotten (with pictures and text)
  • Multiple methods to modify MySQL root password (recommended)
  • How to forget the root password in MySQL 5.7 and change the root password in MySQL 5.7
  • The perfect solution for forgetting the root password of Mysql
  • How to view the root password for MySQL connection
  • Detailed explanation of the idea of ​​installing mysql8.0.11 and changing the root password and connecting navicat for mysql
  • How to forget the root password in Mysql8.0.13 under Windows 10 system

<<:  jQuery realizes the scrolling effect of table row data

>>:  Implementation of FIFO in Linux process communication

Recommend

Detailed explanation of JavaScript Reduce

Table of contents map filter some every findIndex...

First experience of creating text with javascript Three.js

Table of contents Effect Start creating text Firs...

Detailed explanation of VUE Token's invalidation process

Table of contents Target Thought Analysis Code la...

Extract specific file paths in folders based on Linux commands

Recently, there is a need to automatically search...

Detailed explanation of nginx anti-hotlink and anti-crawler configuration

Create a new configuration file (for example, go ...

How to import Excel files into MySQL database

This article shares with you how to import Excel ...

Use Typescript configuration steps in Vue

Table of contents 1. TypeScript is introduced int...

Design Tips: We think you will like it

<br />Looking at this title, you may find it...

How to view files in Docker image

How to view files in a docker image 1. If it is a...

zabbix custom monitoring nginx status implementation process

Table of contents Zabbix custom monitoring nginx ...

MySQL Installer 8.0.21 installation tutorial with pictures and text

1. Reason I just needed to reinstall MySQL on a n...

Mybatis mysql delete in operation can only delete the first data method

Bugs As shown in the figure, I started to copy th...

Detailed explanation of MySQL InnoDB index extension

Index extension: InnoDB automatically extends eac...