Mac computer download MySQL, install MySQL, configure MySQL, root password reset and completely uninstall MySQL

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
insert image description here

You can choose the software version here.
insert image description 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 -aor uname -a | awk -F " " '{print $(NF-1)}'to view.
The author's computer is x86, then download the DMG version, as shown below:
insert image description here

2. Install MySQL under MAC

  1. After downloading, click the pkg file to install it, and click "Continue".
    insert image description here
  2. Keep clicking to continue.
    insert image description here
  3. Click "Agree" and "Continue".
    insert image description here
  4. Enter the power-on password of the machine.
    insert image description here
  5. Here select "Use Legacy Password Encryption" traditional password encryption.
    insert image description here
  6. set password.
    insert image description here
  7. Enter the power-on password of the machine.
    insert image description here
  8. After the installation is complete, click "Close".
    insert image description here
  9. After completing the above operations, there will be a small icon of MySQL in the "System Preferences", click the small icon.
    insert image description here
  10. After clicking the icon, the following interface will appear. If both green dots turn green, it means our installation is successful.
    insert image description here
  11. After the installation is complete, open the terminal and enter: mysql --versionCheck the version number. If the version number is displayed, the installation is normal.

insert image description here

If command not found is displayed, enter in the terminal: /usr/local/mysql/bin/mysqlis the default installation path of mysql.

insert image description here

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

  1. Open the Mac terminal connection, enter in the terminal: mysql
    appears: mysql: command not foundthen you need to configure the environment
  2. MySQL configuration

/usr/local/mysql/bin/Add mysql to the environment variable in

  1. 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.
  2. Then enter in it:export PATH=$PATH:/usr/local/mysql/bin
  3. Press the ESC key to exit the editing mode, then enter: :wq, press command+s to save
  4. Enter: source ~/.bash_profile(reload) to make the environment variable configuration effective
  5. Enter the console mysql --version, and if you mysql Ver 8.0.12 for macos10.13 on x86_64 (MySQL Community Server - GPL)see the version number, it will be successful.
  6. View mysql local location:ps -ef|grep mysql
  7. createtouch .zshrc
  8. Openopen .zshrc
  9. entersource ~/.bash_profile
  10. This way you don't have to open mysql every time

4. Forgot root password reset

  1. Apple -> System Preferences -> Close mysql service (click stop mysql server)
  2. Enter the terminal input: cd /usr/local/mysql/bin/Enter and log in to the administrator
  3. Terminal input: sudo suEnter
  4. 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)
  5. Input: ./mysqlCommand Enter
  6. Input: FLUSH PRIVILEGESCommand Enter
  7. Enter: S ET PASSWORD FOR 'root'@'localhost' = PASSWORD('')command and press Enter, the modification is completed, after restarting the terminal, enter: mysql -u root -pEnter, 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*

Guess you like

Origin blog.csdn.net/qiqizgl777/article/details/129402764