Download MySQL

Download from the official website of MySQL. Considering that the new version may not be compatible with the client, it is recommended to download the 5.x version. Click the Archives to find the historical version.

Select 5.7.31. You are advised to download the DMG file and install it directly.

After clicking On Download, you may be prompted to log in or register. Click on the small print below to Download directly

Double-click the DMG file to enter the installation wizard

The installation

The last step to create a root account will automatically generate a random password, remember to copy the password!

If the password is not copied, resetting the password can be troublesome, as described in a later section.

After the installation is complete, enter the system preferences of the computer, you can see MySQL, click enter.

Start MySQL, and you can set whether to automatically start after startup.

MySQL > uninstall MySQL

If you have installed the wrong version of MySQL and need to uninstall MySQL, first disable MySQL service in system preference Settings, then go to terminal, run the following command:

sudo rm /usr/local/mysql

sudo rm -rf /usr/local/mysql*

sudo rm -rf /Library/StartupItems/MySQLCOM

sudo rm -rf /Library/PreferencePanes/My*

rm -rf ~/Library/PreferencePanes/My*

sudo rm -rf /Library/Receipts/mysql*

sudo rm -rf /Library/Receipts/MySQL*

sudo rm -rf /private/var/db/receipts/*mysql*
Copy the code

The preceding command is used to delete files related to MySQL. If you do not delete the files, subsequent installation of different versions may fail.

If the directory or file does not exist, it has been deleted or has not been created.

Change the password

If you remember the random password generated during installation, you can change the password by following these steps. Note that the client cannot connect to MySQL until the password is changed, so this step is necessary.

Open the terminal and go to the bin directory of mysql:

cd /usr/local/mysql/bin
Copy the code

Execute login command:

mysql -u root -p
Copy the code

Enter the password as prompted, you can see the terminal command input header changed to mysql>

To change the password, enter the semicolon (;) :

set PASSWORD=PASSWORD('123456');
Copy the code

To reset your password

If the random password generated during installation is not remembered, follow these steps to reset the password

MySQL > disable MySQL service

Enter terminal input

cd /usr/local/mysql/bin/
Copy the code

Press Enter to log in to the administrator

 sudo su
Copy the code

Enter the following command to disable mysql authentication

./mysqld_safe --skip-grant-tables &
Copy the code

Mysql restarts automatically when you press Enter (mysql status changes to RUNNING in preferences)

Type the command

./mysql
Copy the code

Press Enter and enter the command

FLUSH PRIVILEGES
Copy the code

Press Enter and enter the command to reset the password

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
Copy the code

Sequel Pro client

The login

Sequel Pro provides client operations for MySQL with a very clean interface and is free! Download the Sequel Pro

Download Sequel Pro.APP and move it directly to the application.

Opening Sequel Pro leads to the following screen, click on FAVORITES ➕ (bookmark the login option for subsequent logins)

Enter Host, UserName and Password, click Save Changes and then Connect to log in

Creating a Database

After login, click Choose Database and Add Database to Add a Database

The new table

Click the plus sign in the lower left corner to create a new table

Set the table name, character set, and engine to utF8MB4:

Create fields and indexes

Insert and update

Table Content can be directly inserted and updated. After selecting Content below, click the plus sign in the lower left corner to insert, and row Content can be directly edited and updated

Execute SQL

Select Query on the menu bar to edit and execute SQL

Check the information

View client execution scripts

Click Console in the upper right corner to view all scripts executed on the client

As follows:

Viewing table information

Select Tabel Info on the menu bar to view table information