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 Strict mode in JavaScript

Table of contents Introduction Using Strict mode ...

About the role of meta in HTML (collected and sorted from the Internet)

W3Cschool explains it this way The <meta> el...

Detailed explanation of ECharts mouse event processing method

An event is an action performed by the user or th...

Vue achieves seamless carousel effect (marquee)

This article example shares the specific code of ...

Take you to understand the event scheduler EVENT in MySQL

The event scheduler in MySQL, EVENT, is also call...

PHP-HTMLhtml important knowledge points notes (must read)

1. Use frameset, frame and iframe to realize mult...

Programs to query port usage and clear port usage in Windows operating system

In Windows operating system, the program to query...

Vue implements the method example of tab routing switching component

Preface This article introduces the use of vue-ro...

Implementation of deploying Apollo configuration center using docker in CentOS7

Apollo open source address: https://github.com/ct...

MySQL query method with multiple conditions

mysql query with multiple conditions Environment:...

An example of how to write a big sun weather icon in pure CSS

Effect The effect diagram is as follows Implement...

How to configure virtual user login in vsftpd

yum install vsftpd [root@localhost etc]# yum -y i...

Solution to the same IP after cloning Ubuntu 18 virtual machine

Preface I recently used a virtual machine to inst...