Mysql.connector.errors.databaseError: 2005 (HY000): неизвестный хост сервера MySQL 'DB' (2) ⇐ Python
Mysql.connector.errors.databaseError: 2005 (HY000): неизвестный хост сервера MySQL 'DB' (2)
[*] Я рассказал о своем веб-приложении Django. />mysql.connector.errors.DatabaseError: 2005 (HY000): Unknown MySQL server host 'db' (2)
[*]This is the same error it is showing when i deployed it to azure
[*]When docker-compose up runs without error locally and the web app works well
< /ul>
Вот мой docker-compose.yml file < /p>
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
< /code>
Вот мой файл utils.py < /p>
import mysql.connector
mydb = mysql.connector.connect(
host="db",
user="root",
passwd="aspilos",
database="aspilos_log",
auth_plugin="mysql_native_password"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT CONCAT('+', PHONE_NUMBER) FROM category2")
results = mycursor.fetchall()
for i in zip(*results):
number = list(i)
number1 = '+2348076548894'
print (number)
< /code>
Вот мой файл sturts.py < /p>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'app',
'USER': 'root',
'PASSWORD': 'aspilos',
'HOST': 'db',
'PORT': '3306',
},
}
Подробнее здесь: https://stackoverflow.com/questions/627 ... ver-host-d
[*] Я рассказал о своем веб-приложении Django. />mysql.connector.errors.DatabaseError: 2005 (HY000): Unknown MySQL server host 'db' (2)
[*]This is the same error it is showing when i deployed it to azure
[*]When docker-compose up runs without error locally and the web app works well
< /ul>
Вот мой docker-compose.yml file < /p>
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
< /code>
Вот мой файл utils.py < /p>
import mysql.connector
mydb = mysql.connector.connect(
host="db",
user="root",
passwd="aspilos",
database="aspilos_log",
auth_plugin="mysql_native_password"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT CONCAT('+', PHONE_NUMBER) FROM category2")
results = mycursor.fetchall()
for i in zip(*results):
number = list(i)
number1 = '+2348076548894'
print (number)
< /code>
Вот мой файл sturts.py < /p>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'app',
'USER': 'root',
'PASSWORD': 'aspilos',
'HOST': 'db',
'PORT': '3306',
},
}
Подробнее здесь: https://stackoverflow.com/questions/627 ... ver-host-d
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение