DEV Community

Gaurav Singh
Gaurav Singh

Posted on

How to setup MySql on MacOS using Brew.

Setting up MySql with MacOs

Step1: Installation from brew.

brew install mysql
Enter fullscreen mode Exit fullscreen mode

Step2: Run this command if we don't want to run MySql in background.

/opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
Enter fullscreen mode Exit fullscreen mode

or for running it in background or at login run this command.

brew services start mysql
Enter fullscreen mode Exit fullscreen mode

I prefer not to run it in background or when i login into my mac.

Step3: Let's check it is working correctly.

Connect to MySQL.

mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

Run the Query.

SHOW DATABASES;
Enter fullscreen mode Exit fullscreen mode

Step4: For turning it off we can use this command (Only if you not running it in background).

/opt/homebrew/opt/mysql/bin/mysqladmin -u root -p shutdown
Enter fullscreen mode Exit fullscreen mode

Step5:(Optional): We can add alias for it for starting it and stopping it.

add alias in ~/.zshrc file or if you bash add it in ~/.bashrc file.

sql-start

alias sql-start='/opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql'
Enter fullscreen mode Exit fullscreen mode

sql-stop

alias sql-stop="/opt/homebrew/opt/mysql/bin/mysqladmin -u root -p shutdown"
Enter fullscreen mode Exit fullscreen mode

By doing this you can start and stop it when need.

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay