How to run a dockerized MySQL server locally, and how to connect your DB tool (Datagrip)

Alexander Baumann
2 min readApr 30, 2020

Tutorial to run a local mysql-server instance via Docker, and connect your DB GUI tool. Let’s get to it:

Pre-reqs:

  • Docker
  • DB GUI tool (I’m using DataGrip/IntelliJ)

1. Pull latest mysql-server docker image

$ docker pull mysql/mysql-server

2. Run mysql-server docker container

$ docker run --name=your-mysql-container-name -d mysql/mysql-server:latest

3. Change root password

Get the current 1-time use password via docker logs

$ docker logs your-mysql-container-name

1-time password after creating a mysql instance

Tunnel into the MySQL container, and connect to the monitor

$ docker exec -it your-mysql-container-name mysql -u root -pEnter Password: <enter GENERATED ROOT PASSWORD shown from docker logs>

Change root-user’s password

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password'

4. Connect your DB tool

Create a user for your DB tool

mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'db-tool-password'
(I kept my username as 'root' )

Flush privileges (for good measure :])

mysql> FLUSH PRIVILEGES;

Through your DB tool: add new data connection, and enter credentials for the new db-tool user

That’s it!

What did I miss? Let me know.

Thank you.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Responses (2)

Write a response

do we not need to expose the port?

Thanks, I need to type:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'db-tool-password'