---
title: "How to Run MySQL on macOS with Docker"
url: https://manytomany.co/blog/how-to-run-mysql-on-macos-with-docker/
published: 2020-11-24
---

# How to Run MySQL on macOS with Docker

24 November 2020

![Cover image for How to Run MySQL on macOS with Docker](https://drw9cjciukmjl.cloudfront.net/2020-11/blog-docker-macos-mysql.png)

If you need to run MySQL on your Mac (e.g. for development) one of the good ways to do it with Docker. It is pretty straightforward to install and use. You can have multiple MySQL instances running side by side. Most importantly they can run different MySQL versions, including version 8. Which is still not supported by another popular option, MAMP. Here is a short guide on how to get it up and running in no time.

## Install Docker

Installing Docker on macOS is pretty straightforward these days. They provide a desktop application with a convenient UI and native means to install it. Grab it here: [](https://docs.docker.com/docker-for-mac/install/)[https://docs.docker.com/docker-for-mac/install/](https://docs.docker.com/docker-for-mac/install/).

## Create a container

Docker runs apps in containers. Create one for your MySQL instance with the following command in the terminal. You might want to alter certain parameters (more on that below).

```bash
docker run \
  --name local-mysql \
  -p 33061:3306 \
  -e MYSQL_ROOT_PASSWORD=p4ssw0rd \
  -d mysql:latest
```

**—name** – defines a name for a running instance. You can pick anything. It should be unique in the scope of your desktop.

**\-p** – this flag sets up port forwarding. MySQL inside the container hangs on the standard port 3306. It is specified _after_ the colon. The port _before_ the colon is the port on your desktop to expose MySQL. It can be anything, including 3306, as long as it is not busy with something else. If you plan to run multiple MySQL instances, it might be a good idea to attach each to a different port in the range of 33061–33069.

**\-e MYSQL\_ROOT\_PASSWORD=** – this is a password for MySQL root user. It can be anything.

**\-d mysql:latest** – here you can specify an [exact MySQL version you want to launch](https://hub.docker.com/_/mysql). Or if you don’t care, you can specify _latest_ to pick whatever latest version is available on Docker Hub at the moment of the container creation.

That’s it, the instance is up and running. More information on configuration options can be found [here](https://hub.docker.com/_/mysql). The instance is running as long as Docker is running, you can start and stop individual instances from Docker Dashboard. Data is persisted between the launches.

It is worth mentioning that Docker on macOS is relatively heavy on resources. Especially on RAM. This is because under the hood it runs a virtualized Linux OS. This is barely noticeable if you have a relatively performant Mac with at least 16 GB of RAM. But for slower models with less RAM running Docker and specifically MySQL in Docker might be inconvenient.

And one more thing.

## Authentication plugin ‘caching\_sha2\_password’ cannot be loaded

This is an issue that you might experience with MySQL 8, while connecting with some clients. Notably _Sequel Pro_ and node.js _mysql_ package. This is because by default MySQL root user uses a new mode of authentication which is not supported by your client. The solution is to change the mode for the root user.

First, connect to MySQL.

```bash
docker exec -it local-mysql bash
mysql -uroot -pp4ssw0rd
```

**local-mysql** – the name of your container.
**p4ssw0rd** – root user password.

Now you should get access to the MySQL console. Run:

```sql
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'p4ssw0rd2';
```

Note that this **will change the password of your root user** to _p4ssw0rd2_. The “alter user” command requires that we specify a different password from what is used, otherwise it will fail. If you want you can call the same command once again with a previous password to change it back.

![Vitalii](https://manytomany.co/vitalii-yellow.png)

## Hi. I'm Vitalii.

I’m a software developer, technical manager and solo entrepreneur. I have been building software products all my life. I am offering **CTO as a Service** at many-to-many.

## Contact me

Let me know what are you looking for. I will reach out to you via the provided email with quote and follow up questions. Alternatively, [book a call](https://calendly.com/many-to-many/intro) or reach me directy by email [hello@manytomany.co](mailto:hello@manytomany.co).

Or using your preferred messaging app:

 [![WhatsApp QR Code](https://manytomany.co/qr/qr-whatsapp.png)](https://wa.me/qr/QH6GQNCO5CZEO1)[WhatsApp](https://wa.me/qr/QH6GQNCO5CZEO1)

 [![Telegram QR Code](https://manytomany.co/qr/qr-telegram.png)](https://t.me/wicharek)[Telegram](https://t.me/wicharek)
