DEV Community

Philip Mutua
Philip Mutua

Posted on • Edited on

11 2

Run MySQL on Port 3307 Using Docker Compose

Sometimes you would like to run MySQL image on different port other than the default one 3306. Suppose you have deployed your back-end application on a server and you find out that there is another service running on port 3306. That was my situation a while back and to solve this I just added the variable MYSQL_TCP_PORT: 3307 under the MYSQL image environments: section as shown below on docker-compose.yml file:


  db:
    restart: always
    image: mysql:5.7

    command: --default-authentication-plugin=mysql_native_password

    environment:
      MYSQL_ROOT_PASSWORD: test#$!
      MYSQL_DATABASE: default_schema
      MYSQL_USER: test
      MYSQL_PASSWORD: test
      MYSQL_TCP_PORT: 3307

    ports:
      - "3307:3307"

Enter fullscreen mode Exit fullscreen mode

Make sure in your application's DB settings you change the database port settings in my case I was developing the back-end service with Django framework here are the settings below:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'default_schema',
        'USER': 'root',
        'PASSWORD': 'test#$!',
        'HOST': 'db',
        'PORT': '3307',
    }
}

Enter fullscreen mode Exit fullscreen mode

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (7)

Collapse
 
medkhabt profile image
LOUKHNATI Mohamed Khalil

Thank you !

Collapse
 
mirzasetiyono profile image
Mirza Setiyono

thanks bud!

Collapse
 
quanty007 profile image
Tshegofatso Legwale

It worked, Thanks

Collapse
 
adahyto profile image
Adam

Hero without a cape. Thank You.

Collapse
 
yassansplus profile image
Yassine Bousaidi

I love you thank you

Collapse
 
tineoc profile image
ChrisTineo

worked <3

Collapse
 
tahmidrana profile image
Tahmidur Rahman

You saved my day. Thank you

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay