webdev sql databses development

RMAG news

Setting up MySql with MacOs

Step1: Installation from brew.

brew install mysql

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

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

brew services start mysql

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

Run the Query.

SHOW DATABASES;

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

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’

sql-stop

alias sql-stop=“/opt/homebrew/opt/mysql/bin/mysqladmin -u root -p shutdown”

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

Leave a Reply

Your email address will not be published. Required fields are marked *