Introduction
MySQL is a database management system based on SQL. like other relational databases, MySQL stores data in tables made up of rows and columns.
If you are doing backend web development, sooner or later you would need to have MySQL installed on your laptop for your dev environment
So in this post, we will be taking a look at how to install MySQL on macOS.
Install MySQL
Installing MySQL is fairly easy thanks to Homebrew. Just type in the following command:
brew install mysql
It may take a while for it to install.
Start MySQL Server
After it's installed, you need to start the MySQL server by using this command:
brew services start mysql
Secure MySQL Server
After starting it, you need to secure the server. By default it comes without a root password, so you will need to make sure it's protected. In order to secure the server, run:
mysql_secure_installation
This procedure may take a while, but it gives a lot of power to make sure you get the best defaults out of the box.
Starting And Stopping MySQL
Because we ran brew services start mysql
to start MySQL, our mac will restart it at reboot. We can stop this from happening by using:
brew services stop mysql
This will also stop MySQL immediately. We can also avoid this by running:
mysql.server start
This is going to start MySQL and will keep it running until the computer is shut down, or until we run:
mysql.server stop
And it will not restart it at reboot.
We can now connect to the server by using:
mysql -u root -p
We will need to write in the root
password after we run this command, and once we are done, we should be inside MySQL. You can use a GUI software that interacts with SQLite database called TablePlus. You can download it on macOS, Windows, and Linux.
Conclusion
This is how to install MySQL on macOS. It is pretty easy and doesn't take that much of your time.
I hope that this post has helped you to get more comfortable with MySQL on macOS.
Comments (0)