Home  >  Article  >  Database  >  mysqlforgot password mac

mysqlforgot password mac

WBOY
WBOYOriginal
2023-05-20 09:48:081644browse

Forgetting MySQL password is a very common problem on Mac systems, especially when you haven't used it for a long time. In this case, if there is no backup password or the password prompt cannot be found, then you will not be able to access the MySQL database. However, don’t worry, this article will detail the solution for forgotten MySQL password on Mac system.

Method 1: Use mysql_secure_installation

If you are using MySQL 5.7 or higher, MySQL will generate a temporary password during installation, which is saved in the system log file. You can find the password by following these steps:

1. Enter the following command in the terminal:

sudo grep 'temporary password' /var/log/mysql/error.log

2. You will see an output similar to the following:

[Note] A temporary password is generated for root@localhost: xxxxxxxx

where, 'xxxxxxxx' is the temporary password .

3. Enter the following command to enter MySQL:

mysql -u root -p

You will be prompted to enter your password. You need to enter the temporary password you just found. Next, the password will be forced to be changed. Please follow the prompts to complete the password change.

Method 2: Reset Password

If you are using MySQL 5.6 or earlier, then you need to follow the following steps to reset your password:

1. Stop MySQL service:

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

2. Use the following command to skip password verification mode to start MySQL:

sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

Note: In this mode, MySQL will not authenticate the user, so anyone can use the database at will. Therefore, you must ensure that you exit this mode and restart the MySQL service immediately after completing the password reset.

3. Connect to MySQL:

mysql -u root

4. Run the following command in MySQL to update the root user's password:

UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';

Note: Replace "your_new_password" with your own new password here.

5. Refresh permissions:

FLUSH PRIVILEGES;

6. Exit MySQL:

exit;

7. Close MySQL:

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

8. Restart MySQL:

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

Now, you can log in to MySQL using your new password.

Summary

MySQL is a database management system that we often use in our daily work, but we often encounter the problem of forgetting the MySQL password. Although this issue may cause some troubles, we can easily forget MySQL password by following the methods mentioned above. Hope this article can be helpful to you.

The above is the detailed content of mysqlforgot password mac. 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