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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs