Trying to init my Django project I was getting this error:
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
I was using this configuration
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'backendtest', # Or path to database file if using sqlite3.
'USER': 'remoteuser', # Not used with sqlite3.
'PASSWORD': '123456789', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
I was using this configuration
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'backendtest', # Or path to database file if using sqlite3.
'USER': 'remoteuser', # Not used with sqlite3.
'PASSWORD': '123456789', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
the solution is pretty simple, change the host value from 'localhost' to 127.0.0.1:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'backendtest', # Or path to database file if using sqlite3.
'USER': 'remoteuser', # Not used with sqlite3.
'PASSWORD': '123456789', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '3306', # Set to empty string for default. Not used with sqlite3.
}
}
Now all works fine
Reference:
No comments:
Post a Comment