Home >Database >Mysql Tutorial >What is the default installation password of mysql?

What is the default installation password of mysql?

PHPz
PHPzOriginal
2023-04-19 15:26:4019212browse

MySQL is a commonly used relational database management system that can run on different operating systems, such as Windows, Linux and Mac OS. When installing MySQL, you will be asked to enter a root user password by default. However, in some cases, we may encounter situations where we have forgotten the password or did not enter the password. In this case, we need to find the Mysql default installation password or reset the password.

1. MySQL default installation password

The default MySQL installation password is automatically generated during installation, and it is called a random password. If you do not enter a password when installing MySQL, the system will generate a default password for you. The password can be found in the MySQL installation log file. In Linux, this file is usually located in the /var/log/ directory and is named mysqld.log.

You can use the following command to view the MySQL installation log file:

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

After executing the above command, the system will output a line similar to the following:

2021-05-03T09:36:15.426149Z 1 [Note] A temporary password is generated for root@localhost: Kd*f!fn1!ar

Among them, Kd*f !fn1!ar is the default temporary password generated by MySQL.

2. Reset MySQL password

If you forget your MySQL root password or cannot access the system’s installation log file, you can follow the steps below to reset the password:

1. Stop MySQL

systemctl stop mysqld

2. Start MySQL using the --skip-grant-tables option. This option skips password verification, allowing you to access MySQL's privileged mode.

mysqld_safe --skip-grant-tables &

3. Log in to MySQL

mysql -u root

4. Update password

use mysql;
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
FLUSH PRIVILEGES;

Where, 'new_password' is the new password you want to set.

5. Restart MySQL

systemctl restart mysqld

Summary

MySQL is a commonly used relational database management system. When installing MySQL, you will be asked to create a root user password by default. . However, in some cases, we may encounter situations where we have forgotten the password or did not enter the password. In this case, we need to find the Mysql default installation password or reset the password. In the above situation, we can achieve this purpose by querying the MySQL installation log file or using privileged mode to reset the password. Therefore, resetting the MySQL password is a relatively simple operation. I hope this article can help readers solve related problems.

The above is the detailed content of What is the default installation password of 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