Linux/Mac MySQL forgotten password command line method to change the password

Linux/Mac MySQL forgotten password command line method to change the password

All prerequisites require root permissions

1. End the mysql process

//Linux
sudo services mysql stop
//Mac
brew services stop mysql

2.mysql background running

mysqld_safe --skip-grant-tables &
mysql

&, means running in the background without opening a new terminal

3. Change password

use mysql;
update user set password = password("new password") where user='root';
flush privileges;

Knowing the original password

Use the mysqladmin command on the command line

mysqladmin -u root -p oldpassword "newpassword"

Or you can enter the MySQL database and modify it directly, refer to the third step above [Change Password]

The above is the method of changing the password of Linux/Mac MySQL command line when you forget the password. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Two ways to change passwords in Linux through Shell script commands
  • A simple way to change the password of mysql just installed in Linux
  • Python implements batch password modification on Linux servers and generates execl
  • Common Linux commands for beginners: password - change password, change user
  • Detailed example of changing Linux account password

<<:  Detailed explanation of docker command to backup linux system

>>:  How to use Dayjs to calculate common dates in Vue

Recommend

Nginx configures the same domain name to support both http and https access

Nginx is configured with the same domain name, wh...

How to lock a virtual console session on Linux

When you are working on a shared system, you prob...

mysql calculation function details

Table of contents 2. Field concatenation 2. Give ...

CUDA8.0 and CUDA9.0 coexist under Ubuntu16.04

Preface Some of the earlier codes on Github may r...

Distinguishing between Linux hard links and soft links

In Linux, there are two types of file connections...

Instructions for using MySQL isolation Read View

Which historical version can the current transact...

Brief analysis of the MySQL character set causing database recovery errors

Importing data with incorrect MySQL character set...

Detailed explanation of CocosCreator Huarongdao digital puzzle

Table of contents Preface text 1. Panel 2. Huaron...

JavaScript flow control (branching)

Table of contents 1. Process Control 2. Sequentia...

The grid is your layout plan for the page

<br /> English original: http://desktoppub.a...

How to smoothly upgrade and rollback Nginx version in 1 minute

Today, let's talk about a situation that is o...

Mysql SQL statement operation to add or modify primary key

Add table fields alter table table1 add transacto...

Solve the problem of using linuxdeployqt to package Qt programs in Ubuntu

I wrote some Qt interface programs, but found it ...

Sample code for implementing music player with native JS

This article mainly introduces the sample code of...