Home  >  Article  >  Database  >  What should I do if I forget mysql default password under centos?

What should I do if I forget mysql default password under centos?

青灯夜游
青灯夜游Original
2020-10-16 09:43:587223browse

Solution: 1. Use the "grep 'temporary password' /var/log/mysqld.log" command to retrieve the initial password during installation; 2. Modify the configuration file "my.cnf" to avoid Log in to the mysql server with your password and use the update command to set a new password.

What should I do if I forget mysql default password under centos?

The operating environment of this tutorial: CentOS 6 system, mysql8 version, Dell G3 computer.

Solution to the forgotten mysql default password under centos

Method 1. Retrieve the initial password during installation:

Execute the following command directly

grep 'temporary password' /var/log/mysqld.log

What should I do if I forget mysql default password under centos?

##Method 2. Configure the my.cnf file, log in to the mysql server without a password, and use the update command Set a new password

1. Modify the configuration file and log in to the mysql server without a password

#vim /etc/my.cnf(Note: windows The modification below is my.ini)

Add any line after [mysqld]

explicit_defaults_for_timestamp=true
skip-grant-tables

Save and exit

Restart mysql

service mysqld restart

Log in to mysql directly

mysql -uroot

What should I do if I forget mysql default password under centos?

2. Change password

use mysql
update user set authentication_string=password(“123456”) where user=“root”;

What should I do if I forget mysql default password under centos?

(Recommended tutorial:

mysql video tutorial)

The above is the detailed content of What should I do if I forget mysql default password under centos?. 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