I've MySQL running through XAMPP, and I've also installed MySQLdb for python installed. I, however cannot figure out a way of using my XAMPP's MySQL for Python. Each time I execute python manage.py runserver
it shows an error:
..2.4c1-py2.7-win32.egg.tmp\MySQLdb\connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
I'm new to Python and these are the settings in settings.py
file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'tester', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'password', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
I'm using Django
. If I use SQLite3 instead of MySQL, it works fine. But I wanted to use MySQL.
EDIT#1
MySQL is using port: 3306
. How do I get them working?
After 5-6 hours of trying, I finally got it working.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'tester', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'password', # 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.
}
}
run command in cmd: python manage.py runserver
, and open the webpage.
Can you check the port because mysql uses default port as 3306 (if not get change manually)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With