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"
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',
}
}
Top comments (7)
Thank you !
thanks bud!
It worked, Thanks
Hero without a cape. Thank You.
I love you thank you
worked <3
You saved my day. Thank you