Install Mysql on Mac, start it, and subsequently change the password

background:

The local mysql was downloaded from homebrew before, but I forgot the password. There was a problem when resetting the password, which caused mysql to be damaged. Therefore, I reinstalled Mysql. This time I chose to reinstall Mysql from the official website.

1. Delete the mysql downloaded by brew

Before reinstalling Mysql, you need to delete the Mysql downloaded by Homebrew. After executing the command, check whether mysql has been deleted. The default path for downloading using homebrew is: /opt/homebrew/opt. If the path is modified, check the specific path.

brew remove mysql

2. Go to the official website and choose the version that suits you to download.

Mysql official website download link Mysql official website download link  follow the steps to install it.

3. Check whether the installation is successful in System Preferences.

 Here you can start and shut down mysql. You will need to enter your mac password during the operation.

4. Use mysql

Problems occur when starting mysql

ERROR 1045 (28000): Access denied for user 'mgx'@'localhost' (using password: NO)

After installing mysql on mac, there is no requirement to enter the mysql login password.

At this time, you need to log in to mysql without a password. First, stop the mysql service and enter the following command in the terminal.

$ cd /usr/local/mysql/bin 
$ sudo ./mysqld_safe --skip-grant-tables
Password: # 输入 Mac 用户的密码

#1 使用
use mysql 

#2 更新自己的密码
UPDATE mysql.user SET authentication_string=PASSWORD("自己想更换的密码") WHERE User='root';

#3 保存执行
FLUSH PRIVILEGES;

After mysql restarts, log in.

Subsequent additions:

For various reasons, I want to change mysql password:

Enter the original password after typing the command:

mysql -uroot -p

 

 Change password, same as above:

 

Guess you like

Origin blog.csdn.net/qq_42405688/article/details/126521204