/

How to Install MySQL on macOS

How to Install MySQL on macOS

Learn how to easily install MySQL on macOS using Homebrew. Follow these step-by-step instructions to set up MySQL on your macOS system.

To begin, you will need to have Homebrew installed on your macOS. If you don’t have it yet, you can install Homebrew by following the instructions on their official website.

Once Homebrew is installed, open your terminal and run the following command:

1
brew install mysql

This command will install MySQL on your system. It may take a while to complete the installation process. After it finishes, you will see a confirmation message.

Now, you can start the MySQL server by running the following command:

1
brew services start mysql

To ensure the security of your MySQL server, we need to set a root password. By default, the server comes without a root password, so it’s important to protect it. Run the following command to secure your MySQL server:

1
mysql\_secure\_installation

This command will guide you through the process of securing your MySQL server. It will prompt you to set a root password, remove anonymous users, disallow remote root login, remove the test database, and reload the privilege tables.

After securing the MySQL server, you may want to stop it from automatically starting at startup. You can do this by running the following command:

1
brew services stop mysql

Alternatively, if you want to manually start and stop the MySQL server, you can use the following commands:

Start MySQL:

1
mysql.server start

Stop MySQL:

1
mysql.server stop

Now, you can connect to your MySQL server using the following command:

1
mysql -u root -p

Replace root with your desired username if you have created additional user accounts. You will be prompted to enter your root password.

For a graphical user interface (GUI) option to interact with your MySQL database, you can use a tool like TablePlus. TablePlus offers a free trial that is limited based on the number of concurrent connections you can make to the database.

Download TablePlus from their official website and install it on your macOS system. Once installed, open TablePlus and click “Create a new connection…”. Select MySQL from the list, enter a name for the connection, and provide the username and password you set for your MySQL server.

Click “Connect” to establish the connection, and you should now be connected to your MySQL server using TablePlus.

Note that for day-to-day usage of your MySQL database, it is recommended to create and use a normal user instead of the root user. We will cover this in a separate tutorial.

tags: [“macOS”, “MySQL installation”, “Homebrew”, “MySQL server”, “macOS Terminal”, “TablePlus”]