Raymond Raymond

Install MySQL on macOS

event 2021-01-17 visibility 388 comment 0 insights toc
more_vert
insights Stats

MySQL is one of the most commonly used open source database in the world. This article provides details about installing MySQL on macOS. The system version is Big Sur v11.1.

Download MySQL

Download MySQL from the following page:

https://dev.mysql.com/downloads/mysql/

Select operating system as macOS and then download macOS 10.15 (x86, 64-bit), DMG Archive from the list. 

2021011754524-Screen Shot 2021-01-17 at 4.45.00 pm.png

You can skip login with Oracle account by click 'No thanks, just start my download' on the bottom of the redirected page.

Install MySQL

  1. In your download folder, you should be able to see the downloaded dmg file:
    2021011754830-image.png
  2. Click the icon to start installation. In the popup window, double click the pkg icon to install the package.

    2021011755206-image.png

  3. Click Allow button.
    2021011755328-image.png
  4. Click Continue button:
    2021011755431-image.png
  5. In Licence tab, click Continue button. And you need to Agree with the licence before you can continue to install.
  6. In Installation Type tab, click Install button.
  7. Input your password. 
  8. Configuration:
    • Choose 'Use Strong Password Encryption." or "Use Legacy Password Encryption." depends on your scenario. For my purpose, I will use the legacy option.
    • Input root user password. For example, P@ssw0rd.
      2021011760037-image.png
    • Click Finish button to finish configurations.
  9. Click Continue button.
  10. Click Close button to finish the setup.
    2021011760209-image.png

You can keep or remove the installer.

Add mysql command

To use MySQL CLI, run the following command to add it to Bash profile:

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> ~/.bash_profile

And then reload the profile:

. ~/.bash_profile

Connect to MySQL

As part of the installation, MySQL service is started after finalising the installation. 

Run the following command to check the status to make sure the service is running successfully:

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

Now run the following command to connect to MySQL through shell:

mysql -u root -pP@ssw0rd

Remember to replace password with your own one. The output should look similar as the following one:

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 13

Server version: 8.0.22 MySQL Community Server - GPL


Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

+--------------------+

4 rows in set (0.01 sec)


mysql> 

MySQL service commands on macOS

The commands are different compared with Linux system.

Start service

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

Stop service

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

Restart service

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


More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts