Solution to forgetting MySQL root password in MACOS

Solution to forgetting MySQL root password in MACOS

MySQL is a relational database management system developed by Swedish company MySQL AB and currently a product of Oracle. MySQL is one of the most popular relational database management systems. In terms of WEB applications, MySQL is the best RDBMS (Relational Database Management System) application software.

MySQL is a relational database management system that stores data in different tables instead of putting all the data in one large warehouse, which increases speed and flexibility.

The SQL language used by MySQL is the most commonly used standardized language for accessing databases. MySQL software adopts a dual licensing policy and is divided into community edition and commercial edition. Due to its small size, fast speed, low total cost of ownership, and especially its open source nature, MySQL is generally chosen as the website database for the development of small and medium-sized websites.

After installing MySQL on Mac, the software will generate a default password for us. However, when I used Navicat to establish a connection, it prompted that the password was invalid. I had no choice but to change the default database password.

Next, record the entire root password modification process.

The mysql service must be stopped before starting the following steps!

 cd /usr/local/mysql/bin/
 sudo su
 ./mysqld_safe --skip-grant-tables & //This step is used to bypass permission verification./mysql -uroot //Log in as root. No password is required because of the third step. There is no need to add ./mysql in front of the command after this use mysql;
 update user set authentication_string='123456' where User='root';

The versions circulating on the Internet are all set password = ''. This way of writing always gives an error saying that the 'password' column does not exist!

Finally, using the SQL command to check, it was found that there was only an authentication_string field, but no password field.

After executing the previous step, I thought I could log in, but when I tested the connection with navicat, the following error occurred:

ERROR 1862 (HY000): Your password has expired. To log in you must
change it using a client that supports expired passwords.

So the following steps are needed

 cd /usr/local/mysql/bin/
 sudo su
 ./mysql -uroot -p123456
 set password = password('123456')

Username: root, Password: 12345

Modification successful

Supplement: Although the above modification was successful, there were still many detours. The above is just a record of the whole process. Let's summarize the simplest and most effective method below.

This process was heartbreaking. There was a ton of information on the Internet, but everyone had their own wrong methods. I tried for a long time but couldn't find the right one. Just when I was about to break through my psychological defenses and look up the MySQL documentation, I succeeded. There is no article that tells me the complete answer. I referred to several guides and built the car behind closed doors. Give yourself a thumbs up. Without further ado, follow me step by step.

1. Shut down the MySQL server

sudo /usr/local/mysql/support-files/mysql.server stop


You can also turn it off in MySQL in System Preferences.

2.cd /usr/local/mysql/bin to enter the directory

3. sudo su to obtain permissions

4. ./mysqld_safe --skip-grant-tables & restart the server

5. Reopen the terminal,

Configuration short command:

alias mysql=/usr/local/mysql/bin/mysql

6. Enter mysql to enter mysql command mode

7. Use mysql to enter the mysql database

8. flush privileges; probably means to obtain permissions, otherwise he won't let you change it.

9. set password for 'root'@'localhost'=password('新密碼'); complete the modification

10. Damn, I finally finished the revision.

Okay, I have taught you the method, I hope it will be helpful to you.

You may also be interested in:
  • How to change the root password of Mysql5.7.10 on MAC
  • MySQL initialization password operation under Mac
  • How to solve the problem of forgetting the root password of Mysql on 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

<<:  Several ways to implement inheritance in JavaScript

>>:  The simplest solution to the problem that Sublime Text cannot input Chinese in Ubuntu

Recommend

Introduction to JWT Verification Using Nginx and Lua

Table of contents Preface Lua Script nignx.conf c...

How to develop uniapp using vscode

Because I have always used vscode to develop fron...

Summary of Vue 3 custom directive development

What is a directive? Both Angular and Vue have th...

Rules for registration form design

I finished reading "Patterns for Sign Up &...

How to run Linux commands in the background

Normally, when you run a command in the terminal,...

Centos7.3 automatically starts or executes specified commands when booting

In centos7, the permissions of the /etc/rc.d/rc.l...

An article to understand Linux disks and disk partitions

Preface All hardware devices in the Linux system ...

Several ways to set the expiration time of localStorage

Table of contents Problem Description 1. Basic so...

VM VirtualBox virtual machine mount shared folder

One environment Install VMware Tools on CentOS 7 ...

Description of the execution mechanisms of static pages and dynamic pages

1. A static page means that there are only HTML ta...

Introduction to HTML DOM_PowerNode Java Academy

What is DOM? With JavaScript, you can reconstruct...

Analysis and description of network configuration files under Ubuntu system

I encountered a strange network problem today. I ...