Table of contents
1. MySQL download
Download the MySQL version of the corresponding model from the official website
. Click Product Version to select the version of the corresponding model to install (for example: the author’s Mac here is an old version of MacOS 10.13
You can choose the software version here.
We can see that there are two installation packages (DMG and TAR) with different architectures. If you don’t know whether your computer is TAR or X86, you can open the terminal and enter: uname -a
or uname -a | awk -F " " '{print $(NF-1)}'
to view.
The author's computer is x86, then download the DMG version, as shown below:
2. Install MySQL under MAC
- After downloading, click the pkg file to install it, and click "Continue".
- Keep clicking to continue.
- Click "Agree" and "Continue".
- Enter the power-on password of the machine.
- Here select "Use Legacy Password Encryption" traditional password encryption.
- set password.
- Enter the power-on password of the machine.
- After the installation is complete, click "Close".
- After completing the above operations, there will be a small icon of MySQL in the "System Preferences", click the small icon.
- After clicking the icon, the following interface will appear. If both green dots turn green, it means our installation is successful.
- After the installation is complete, open the terminal and enter:
mysql --version
Check the version number. If the version number is displayed, the installation is normal.
If command not found is displayed, enter in the terminal: /usr/local/mysql/bin/mysql
is the default installation path of mysql.
Configure the default path:
cd /usr/local/bin/
sudo ln -fs /usr/local/mysql/bin/mysql mysql
Close the MySQL service:
sudo /usr/local/mysql/support-files/mysql.server stop
3. Configure MySQL in MAC environment
- Open the Mac terminal connection, enter in the terminal:
mysql
appears:mysql: command not found
then you need to configure the environment - MySQL configuration
/usr/local/mysql/bin/
Add mysql to the environment variable in
- Open the terminal, enter in the terminal:
sudo vim ~/.bash_profile
(execute root authority, .bash_profile under the root directory of the current user), press Enter to enter the password, after opening, press the i key to enter the edit mode.- Then enter in it:
export PATH=$PATH:/usr/local/mysql/bin
- Press the ESC key to exit the editing mode, then enter:
:wq
, press command+s to save- Enter:
source ~/.bash_profile
(reload) to make the environment variable configuration effective- Enter the console
mysql --version
, and if youmysql Ver 8.0.12 for macos10.13 on x86_64 (MySQL Community Server - GPL)
see the version number, it will be successful.- View mysql local location:
ps -ef|grep mysql
- create
touch .zshrc
- Open
open .zshrc
- enter
source ~/.bash_profile
- This way you don't have to open mysql every time
4. Forgot root password reset
- Apple -> System Preferences -> Close mysql service (click stop mysql server)
- Enter the terminal input:
cd /usr/local/mysql/bin/
Enter and log in to the administrator - Terminal input:
sudo su
Enter - Enter:
./mysqld_safe --skip-grant-tables &
command to disable the mysql verification function, press Enter and mysql will automatically restart (the status of mysql in the preference setting will change to running) - Input:
./mysql
Command Enter - Input:
FLUSH PRIVILEGES
Command Enter - Enter: S
ET PASSWORD FOR 'root'@'localhost' = PASSWORD('')
command and press Enter, the modification is completed, after restarting the terminal, enter:mysql -u root -p
Enter, and then enter the password set before to start successfully.
5. Completely uninstall MySQL under MAC
Open a terminal window and do the following in sequence:
Use mysqldump to back up your database as a text file!
Stop the database server
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/My*
The last three lines are very important: you can completely remove the old version, after which you can reinstall the new version
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*