[Django]-OperationalError, Django Cannot Connect to MySQL Database

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!

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.

👤Calvin Cheng

Leave a comment