Home >Database >Mysql Tutorial >What to do if you forget your password for Linux/Mac MySQL

What to do if you forget your password for Linux/Mac MySQL

巴扎黑
巴扎黑Original
2017-05-14 14:19:251036browse

Linux/Mac What should I do if I forget my password for MySQL? This article mainly introduces the solution to the MySQL forgotten password. The command line modification has certain reference value. Interested friends can refer to

Linux/Mac What to do if MySQL forgets the password? Don’t worry, here’s how to change your password using the command line.

All prerequisites require root permissions

1. End the mysql process


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

2. Mysql runs in the background


##

mysqld_safe --skip-grant-tables &
mysql

&, which means it runs in the background and does not open a new terminal

3. Change the password


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

If you know the original password

Use the mysqladmin command on the command line



mysqladmin -u root -p oldpassword "newpassword"

Or you can enter the mysql database to modify it directly, refer to the third part above [Change Password]

The above is the detailed content of What to do if you forget your password for Linux/Mac MySQL. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn