mac MySQL change password

Introduction: MySQL is a commonly used relational database management system. In some cases, you may need to shut down the MySQL service or change the root password. This article will show you the steps on how to do these things.

Step 1: Shut down the MySQL service

  • Open the MySQL software and close it.
    insert image description here

  • Or shut down the MySQL service with the following command:

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

Step 2: Enter the MySQL bin folder

Open a terminal and enter the MySQL bin folder with the following command:

cd /usr/local/mysql/bin

Step 3: Get Permissions

Get administrator privileges with the following command:

`sudo su`

Step 4: Enter Safe Mode

Enter the following command in Terminal to enter safe mode:

./mysqld_safe --skip-grant-tables &

Step 5: Open a new terminal window and enter MySQL

Open a new terminal window and enter the following command to enter MySQL:

mysql

Step 6: Enter the mysql library in MySQL

At the MySQL command prompt, enter the following command to enter MySQL's mysql repository:

use mysql;

Step 7: Refresh MySQL system permissions

In the mysql repository, enter the following command to refresh the MySQL system privileges:

flush privileges;

Step 8: Change the root password

In the mysql library, enter the following command to change the root password. will be your_new_passwordreplaced with the new password you want to set:

alter user 'root'@'localhost' identified by 'your_new_password';

Precautions:

  • The new password should be a strong password, containing at least uppercase and lowercase letters, numbers and special characters, and the length should be more than 6 characters to increase security.
  • Please ensure you have the appropriate permissions to perform the above actions.
  • If you run into any issues, make sure you have the correct permissions and that the MySQL installation path matches the one provided in the tutorial.

Hope this tutorial helps you!

Guess you like

Origin blog.csdn.net/qq_40963664/article/details/131683255