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

Summary of common tool functions necessary for front-end development

1. Time formatting and other methods It is recomm...

Analysis of the principle of using PDO to prevent SQL injection

Preface This article uses pdo's preprocessing...

Tutorial on how to quickly deploy a Nebula Graph cluster using Docker swarm

1. Introduction This article describes how to use...

centos 7 modify sshd | prohibit root login and sshd port script definition

1. Create a new user wwweee000 [root@localhost ~]...

Use of Linux read command

1. Command Introduction The read command is a bui...

Methods and steps for Etcd distributed deployment based on Docker

1. Environmental Preparation 1.1 Basic Environmen...

Example of removing json backslash in php

1. Remove backslashes through the "stripslas...

MySQL 8.0.21 free installation version configuration method graphic tutorial

Six steps to install MySQL (only the installation...

CSS float (float, clear) popular explanation and experience sharing

I came into contact with CSS a long time ago, but...

HTML table markup tutorial (2): table border attributes BORDER

By default, the border of the table is 0, and we ...

React+Amap obtains latitude and longitude in real time and locates the address

Table of contents 1. Initialize the map 2. Map Po...

Use of MySQL DDL statements

Preface The language classification of SQL mainly...

An IE crash bug

Copy code The code is as follows: <style type=...

JS realizes the case of eliminating stars

This article example shares the specific code of ...

Implementation of vscode custom vue template

Use the vscode editor to create a vue template, s...