How to solve the problem of forgetting the root password of Mysql on Mac

How to solve the problem of forgetting the root password of Mysql on Mac

I haven't used mysql on my computer for a long time and I have forgotten my password. But it doesn't matter, we can reset our password

The principle is to open the MySQL service in a safe way and then update the table storing the password.

First we need to shut down the original MySQL service, System Preferences->MySQL->Stop MySQL Server

Then open a Terminal, open mysql in safe mode, and no password is required when connecting

sudo mysqld_safe --skip-grant-tables

Then open another Terminal and update the password

mysql -u root
UPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE User='root';
FLUSH PRIVILEGES;

In the above format, you only need to modify your_new_password

If the Mysql version is before V5.7.9, please use the following sql statement

UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';

Finally restart Mysql and give it a try

mysql -uroot -pyour_new_password

Mission accomplished! ! ! !

In addition, here is the solution provided by netizens:

step1:

Shut down the MySQL service: Apple->System Preferences->Click MySQL at the bottom. In the pop-up page, shut down the MySQL service (click Stop MySQL Server).

step2:

Enter the terminal and type: cd /usr/local/mysql/bin/
After pressing Enter, log in with administrator privileges sudo su
After pressing Enter, enter the following command to disable the mysql authentication function./mysqld_safe ./mysqld_safe --skip-grant-tables &
After pressing Enter, MySQL will automatically restart (the status of MySQL in the preferences will become running)

step3:

Enter the command ./mysql
After pressing Enter, enter the command FLUSH PRIVILEGES;
After pressing Enter, enter the command SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密碼');

After completing the above steps, the password has been changed successfully. Now you can use the newly set password to log in to MySQL.

You may also be interested in:
  • How to change the root password of Mysql5.7.10 on MAC
  • Solution to forgetting MySQL root password in MACOS
  • MySQL initialization password operation under Mac
  • What to do if you forget the initial password of MySQL on MAC
  • What to do if you forget the initial password of MySQL on MAC
  • How to modify the initial password of MySQL on MAC
  • Solution to forgetting the root password of MySQL5.7 on Mac
  • How to reset mysql password after forgetting it on Mac
  • How to set password for mysql version 5.6 on mac

<<:  15 Vim quick reference tables to help you increase your efficiency by N times

>>:  Native js drag and drop function to create a slider example code

Recommend

Introduction to root directory expansion under Linux system

1. Check Linux disk status df -lh The lsblk comma...

CSS3 uses transform to create a moving 2D clock

Now that we have finished the transform course, l...

How to install mysql5.7.24 binary version on Centos 7 and how to solve it

MySQL binary installation method Download mysql h...

CSS pseudo-class: empty makes me shine (example code)

Anyone who has read my articles recently knows th...

UrlRewriter caching issues and a series of related explorations

When developing a website function, the session c...

How to gracefully and safely shut down the MySQL process

Preface This article analyzes the process of shut...

Install mysql 5.6 from yum source in centos7.4 system

System environment: centos7.4 1. Check whether th...

Solve the problem of HTML automatic formatting after saving in vscode

The version of vsCode has been updated in recent ...

Should I use distinct or group by to remove duplicates in MySQL?

Preface About the performance comparison between ...

jQuery simulates picker to achieve sliding selection effect

This article shares the specific code of jQuery t...

MySQL Series 12 Backup and Recovery

Table of contents Tutorial Series 1. Backup strat...

React-Native environment setup and basic introduction

Environment Preparation 1. Environment Constructi...

Vue custom directive details

Table of contents 1. Background 2. Local custom i...

How to Monitor Linux Memory Usage Using Bash Script

Preface There are many open source monitoring too...

A quick solution to the problem of PC and mobile adaptation

When making a web page, we usually need to consid...