3

I am working a Django tutorial and I want to connect my project to a MySQL database. I did everything as told by the djangoproject tutorial to connect to database. When running python manage.py syncdb , however, I got the following error:

_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)") 

What seems problematic? I have XAMMP downloaded and I have created databases through XAMMP before but I don't know how that affects the connection with Django.

Thanks.

1
  • For some reasons I can't remember, I used 3308 instead of 3306 and it worked after attempting to resolve the problem for two hours. Commented May 25, 2013 at 12:53

2 Answers 2

5

Actually under the settings.py, I set HOST to "127.0.0.1" and PORT to 3306, filled out the rest of DATABASE portion and it worked!

Sign up to request clarification or add additional context in comments.

Comments

3

If you are using Windows 7, you might run into problems if your MySQL is configured to use named pipes. Set your MySQL config to use TCP instead.

 Once your reconfigured MySQL allows local network connections, your MySQLdb should work over TCP.  

It doesn't seem to be able to use Windows 7 named pipes, although the "mysql" command line client can. There may be a bug.  This wouldn't be noticed unless MySQL was configured without network connections, which is rare.  I set up MySQL that way on a development machine with a local MySQL instance.

A detailed article here - http://interconnectit.com/764/using-mysql-workbench-with-xampp/ - shows you the screen where you can switch your Connection Method from named pipes (Local Socket/Pipes) to TCP/IP via Xampp.

enter image description here

Alternatively, if using named pipes (windows) or sockets (linux/mac) for your python/django app to connect to your MySQL is important to you and you do not want to change your connection method to TCP/IP, you should try setting the servername to "." in your xampp's my.conf configuration file; instead of "localhost" or "127.0.0.1". Using pipes/sockets bypasses the TCP/IP network protocol, giving slightly better performance.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.