How to change the root user's password in MySQL

How to change the root user's password in MySQL

Method 1: Use the SET PASSWORD command

mysql> set password for username@localhost = password('new password');
-- Examplemysql> set password for root@localhost = password('123');

Method 2: Using mysqladmin

mysql> mysqladmin -u username -p old password password new password;
-- Examplemysql> mysqladmin -uroot -p123456 password 123;

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;

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. Type 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 can no longer be moved) and go to the mysql\bin directory.
  5. Type mysql and press Enter. If successful, the MySQL prompt will appear>
  6. Connection permission database: use mysql;
  7. Change password: update user set password=password("123") where user="root";
  8. Refresh privileges (required step): flush privileges;
  9. Exit: quit
  10. 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 details of how to modify the password of the root user in MySQL. For more information about modifying the password of the root user in MySQL, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Introduction to some operations of MySQL secure password input
  • How to change the secure processing password in MySQL 5.6
  • Quick solution for forgetting MySQL8 password
  • How to retrieve password for mysql 8.0.22 on Mac
  • Detailed explanation of MySQL 8.0 password expiration policy
  • MySQL implements an example method of logging in without a password
  • How to reset the root password in Linux mysql-5.6
  • How to safely shut down MySQL
  • How to gracefully and safely shut down the MySQL process
  • It's the end of the year, is your MySQL password safe?

<<:  How to use gdb to debug core files in Linux

>>:  JavaScript to achieve digital clock effects

Recommend

Detailed explanation of CSS3 Flex elastic layout example code

1. Basic Concepts //Any container can be specifie...

js implements the classic minesweeper game

This article example shares the specific code of ...

The past two years with user experience

<br />It has been no more than two years sin...

How to hide and remove scroll bars in HTML

1. HTML tags with attributes XML/HTML CodeCopy co...

Build a WebRTC video chat in 5 minutes

In the previous article, I introduced the detaile...

MySQL Series 11 Logging

Tutorial Series MySQL series: Basic concepts of M...

Example of using CSS3 to achieve shiny font effect when unlocking an Apple phone

0. Introduction August 18, 2016 Today, I noticed ...

A brief discussion on the magical slash in nginx reverse proxy

When configuring nginx reverse proxy, the slashes...

Summary of basic knowledge points of Linux group

1. Basic Introduction of Linux Group In Linux, ev...

Solution to the welcome to emergency mode message when booting CentOS7.4

Today I used a virtual machine to do an experimen...

Appreciation of the low-key and elegant web design in black, white and gray

Among classic color combinations, probably no one...

Detailed steps to install Nginx on Linux

1. Nginx installation steps 1.1 Official website ...

Methods and steps to access Baidu Maps API with JavaScript

Table of contents 1. Baidu Map API Access 2. Usin...

How to use nginx to simulate blue-green deployment

This article introduces blue-green deployment and...

Why MySQL does not recommend deleting data

Table of contents Preface InnoDB storage architec...