简体   繁体   English

mysql.connector.errors.InterfaceError:2003:无法连接到“127.0.0.1:3306”上的 MySQL 服务器(111 连接被拒绝)

[英]mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (111 Connection refused)

  • I used mysql connector in my django web app.我在我的 django web 应用程序中使用了 mysql 连接器。
  • I've dockerized the app and mysql is throwing this error.我已经对应用程序进行了 docker 化,并且 mysql 抛出了这个错误。
  • I've tried restarting mysql server,我试过重启 mysql 服务器,
  • i've also used 127.0.0.1 instead of localhost, it still throws the我还使用了 127.0.0.1 而不是 localhost,它仍然会抛出
    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 up”,它带来了这个错误 mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (111 Connection denied)
  • "docker-compose build" runs fine but "docker-compose up" and python manage.py runserver" throws the mysql error “docker-compose build”运行良好,但“docker-compose up”和 python manage.py runserver”抛出 mysql 错误

Here is my utils.py file这是我的 utils.py 文件

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这是我的 docker-compose.yml 文件

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这是我的 settings.py 文件

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'app',
'USER': 'root',
'PASSWORD': 'aspilos',
'HOST': 'db',
'PORT': '3306',
},

}

In your utils.py, you are using host as "127.0.0.1", change it to db .在您的 utils.py 中,您将主机用作“127.0.0.1”,将其更改为db

mydb = mysql.connector.connect(
   host="db",
   user="root",
   passwd="aspilos",
   database="aspilos_log"
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mysql.connector.errors.InterfaceError:2003:无法连接到Scrapinghub上'127.0.0.1:3306'上的MySQL服务器 - mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' on Scrapinghub 如何修复 InterfaceError:2003:无法连接到“127.0.0.1:3306:3306”上的 MySQL 服务器(11001 getaddrinfo 失败) - How to fix InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306:3306' (11001 getaddrinfo failed) 2003:无法连接到“192.168.0.14:3306”上的 MySQL 服务器(111 连接被拒绝) - 2003: Can't connect to MySQL server on '192.168.0.14:3306' (111 Connection refused) mysql.connector.errors.interfaceerror 2003 - mysql.connector.errors.interfaceerror 2003 mysql.connector.errors.DatabaseError: 2003 (HY000): 无法连接到“127.0.0.1”上的 MySQL 服务器 (111) - mysql.connector.errors.DatabaseError: 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) Python & MySQL mysql.connector.errors.InterfaceError:2013:在查询期间丢失与 Z7637AZ41A服务器的连接 - Python & MySQL mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query Docker MYSQL [2003] 无法连接到 MySQL 服务器(111 连接被拒绝) - Docker MYSQL [2003] Can't connect to MySQL server (111 Connection refused) PyMySQL:- OperationalError: (2003, “无法连接到‘本地主机’上的 MySQL 服务器([Errno 111] 连接被拒绝)”) - PyMySQL:- OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)") InterfaceError:2003:无法连接到“ localhost:3306”上的MySQL服务器(13权限被拒绝) - InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (13 Permission denied) Python:“mysql.connector.errors.InterfaceError: 2003”当我的端口是数字时 - Python: "mysql.connector.errors.InterfaceError: 2003" when my port is a number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM