Docker for Mac allows you to build, debug, and test Dockerized apps on a Mac OS. Check out how to set it up to use MySQL!
Hello Friends,In this video tutorial, you will learn to install mysql database server on mac os x catalina. I have explained the whole process of installatio. In this post we will learn how to How To Install MySQL on Mac OS X. The same procedure can be used for installing MySQL on Mac OS X.How to add MySQL to $PAT. Download the MySQL DMG for Mac OS X. Install Preference Pane. Open System Preferences → MySQL. Ensure the MySQL Server is running. Optionally, you can enable MySQL to start automatically. The README also suggests creating aliases for mysql and mysqladmin. This short tutorial shows how to install MySQL on a Mac using Homebrew and how to verify it is running using Sequel Pro. Install Homebrew. Homebrew is a package manager for Mac and serves a.
Join the DZone community and get the full member experience.
Mysql Mac Setup Windows 10Join For Free
This article will provide step-by-step instructions on how to set up MySQL in Docker for Mac and how to access MySQL from the host (Mac) OS. This article assumes that you know what Docker is, understand how to use MySQL, and understand how to use SQL commands to create a user, create a database, and grant privileges.
Before we jump into action, let's learn the basics of Docker for Mac.
Why Docker For Mac?
Docker is an abstraction on top of Linux containers to simplify using and managing containers. Mac OS is Unix and it doesn't have containers directly, as in Linux OS (Ubuntu, Fedora, Core OS, etc.). Hence, a Virtual Machine is set up on top of Mac OS and has an instance (Guest OS) of Linux to run containers. To simplify Docker and Virtual Machine setup in Mac OS, Docker for Mac was created.
According to this documentation, Docker for Mac is:
...an easy-to-install desktop app for building, debugging, and testing Dockerized apps on a Mac. Docker for Mac is a complete development environment deeply integrated with the MacOS Hypervisor framework, networking, and filesystem. Docker for Mac is the fastest and most reliable way to run Docker on a Mac.
Now that we have background info, let's see how to set up MySQL in Docker for Mac.
Follow these instructions to install Docker for Mac. After installing Docker for Mac, please verify the information below.
$ is the prompt. Ignore it and copy the rest of the line.
Run the MySQL image using the
docker run command.
This will install the latest version of the MySQL image in Docker Hub. As of this writing, it was 5.7.
If the image was not already available, this command will download the image and run it.
You can verify if MySQL has started using the
docker ps command below.
Log into MySQL within the docker container using the
docker exec command:
Remember, when we created and ran the MySQL container, we provided
Create a database and user, and grant privileges in MySQL (from within the container).
Log into MySQL if you haven't already. After login, the
mysql> prompt shows up:
I create a user named
arun, grant all privileges, and quit.
Important: This step is required to log into MySQL from outside the container. The root user will not be able to log in from the host OS (Mac OS). Use
% instead of
localhost in [email protected]
Connect to MySQL running in Docker from MySQL Workbench. If MySQL Workbench is not installed yet, follow these instructions to install it.
Open MySQL Workbench and click on + to add a new connection. Enter all the information as stated in the screenshot and click on Test Connection.
Enjoy creating and accessing your MySQL database running in a Docker container! For more MySQL
docker run options, refer to here.
If there is something that can be improved in this article, please provide your thoughts in the comments.
Opinions expressed by DZone contributors are their own.
Popular on DZone
On macOS, you can install MySQL easily using Homebrew.
Mysql Mac Setup Guide
The above command should take a while, then print something like this:
You can now start the MySQL server by running:
Now we need to secure the MySQL server. By default the server comes without a root password, so we need to make sure it’s protected.
The procedure can take a while, but it gives a lot of power to make sure you get the best defaults out of the box:
Since we used
brew services start mysql to start MySQL, your Mac will re-start it at reboot. You can run:
to stop this from happening, and also to immediately stop MySQL.
You can also avoid this daemon mode (that’s what we call programs that always run in the background and restart when the computer is restarted) by running:
This will start MySQL and will keep it running until the computer is shut down, or until you run:
and it will not re-start it at reboot.
It’s up to you to decide which one you prefer.
Now you can connect to the server using the command:
You will need to type the
root user password after you run this command, and once you are done you should see this screen:
A great GUI (graphical) software we can use to interact with a SQLite database is TablePlus.
It comes with a free trial that’s perfect for our usage, because it’s not time-based but rather it limits the amount of concurrent connections you can make to the database.
Download it from https://tableplus.com. I know there are macOS, Windows and Linux versions.
Click “Create a new connection…” and select MySQL in the list:
then set a name for the connection, and enter “root” and the password you set previously:
Connect, and you should be connected to MySQL!
Mysql Mac Setup Online
Note that we are connected using the
root user, which should only be used for administration purposes.
Day to day use of a database should be done using a normal user. We’ll see it in a separate tutorial.