- I used mysql connector in my django web app.
- I've dockerized the app and mysql is throwing this error.
- I've tried restarting mysql server,
- i've also used 127.0.0.1 instead of localhost, it still throws the
same error. - I'm trying to run "docker-compose up" here and it's bringing this error mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (111 Connection refused)
- "docker-compose build" runs fine but "docker-compose up" and python manage.py runserver" throws the mysql error
Here is my utils.py file
import mysql.connector
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="aspilos",
database="aspilos_log"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT PHONE_NUMBER FROM category2")
results = mycursor.fetchall()
for i in zip(*results):
number = list(i)
number1 = '+2348076548894'
print (number)
Here is my docker-compose.yml file
version: '3.4'
services:
db:
image: mysql
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'app'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'aspilos'
MYSQL_ROOT_PASSWORD: 'aspilos'
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/aspilos
ports:
- "8000:8000"
depends_on:
- db
Here is my settings.py file
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'app',
'USER': 'root',
'PASSWORD': 'aspilos',
'HOST': 'db',
'PORT': '3306',
},
}