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

React Native scaffolding basic usage detailed explanation

Build the project Execute the command line in the...

Set the width of the table to be fixed so that it does not change with the text

After setting the table width in the page to width...

JavaScript super detailed implementation of web page carousel

Table of contents Creating HTML Pages Implement t...

7 Ways to Write a Vue v-for Loop

Table of contents 1. Always use key in v-for loop...

Getting Started Tutorial for Beginners ④: How to bind subdirectories

To understand what this means, we must first know ...

Javascript asynchronous programming: Do you really understand Promise?

Table of contents Preface Basic Usage grammar Err...

How to regularly clean up docker private server images

Using CI to build docker images for release has g...

Mysql sorting to get ranking example code

The code looks like this: SELECT @i:=@i+1 rowNum,...

Use of Linux sed command

1. Function Introduction sed (Stream EDitor) is a...

React realizes secondary linkage effect (staircase effect)

This article shares the specific code of React to...

Detailed installation and configuration tutorial of PostgreSQL 11 under CentOS7

1. Official website address The official website ...

MySQL 4G memory server configuration optimization

As the number of visits to the company's webs...

Detailed explanation of the pitfalls of mixing npm and cnpm

Table of contents cause reason Introduction to NP...

Vue3 compilation process-source code analysis

Preface: Vue3 has been released for a long time. ...