Install MySQL on macOS
insights Stats
SQL relational databases incl. SQLite, SQL Server, MySQL, PostgreSQL, Oracle, etc.
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.
You can skip login with Oracle account by click 'No thanks, just start my download' on the bottom of the redirected page.
Install MySQL
- In your download folder, you should be able to see the downloaded dmg file:
Click the icon to start installation. In the popup window, double click the pkg icon to install the package.
- Click Allow button.
- Click Continue button:
- In Licence tab, click Continue button. And you need to Agree with the licence before you can continue to install.
- In Installation Type tab, click Install button.
- Input your password.
- 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.
- Click Finish button to finish configurations.
- Click Continue button.
- Click Close button to finish the setup.
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