DATABASE_PORT ignored?

56 views
Skip to first unread message

msoulier

unread,
Feb 16, 2008, 3:34:40 PM2/16/08
to Django users
I have a site where I need to use the mysql tcp port of 3306 instead
of the unix domain socket, to talk to mysql. So, I did this in my
settings.py

DATABASE_HOST = 'localhost'
DATABASE_PORT = 3306

Unfortunately, it seems to be ignored.

_mysql_exceptions.OperationalError: (2002, "Can't connect to local
MySQL server through socket '/tmp/mysql.sock' (2)")

Is it possible to tell Django to tell MySQLdb to use the tcp port?

Thanks,
Mike

Malcolm Tredinnick

unread,
Feb 16, 2008, 3:41:17 PM2/16/08
to django...@googlegroups.com

On Sat, 2008-02-16 at 12:34 -0800, msoulier wrote:
> I have a site where I need to use the mysql tcp port of 3306 instead
> of the unix domain socket, to talk to mysql. So, I did this in my
> settings.py
>
> DATABASE_HOST = 'localhost'
> DATABASE_PORT = 3306
>
> Unfortunately, it seems to be ignored.

Welcome to the always interesting world of strange MySQL decisions. This
isn't a Django problem, it's normal MySQL client library behaviour. When
the host is "localhost", it will never use TCP/IP, only Unix sockets.
Even though localhost is a perfectly valid domain name.

Instead, you need to use 127.0.0.1 to force the connection to go via
TCP/IP. I'm pretty sure, without having tested it, that Django will be
fine with that (setting the HOST string to an IP address). We just pass
that information straight through to the MySQLdb python wrapper, so
whatever it accepts, we accept.

Malcolm

--
Success always occurs in private and failure in full view.
http://www.pointy-stick.com/blog/

msoulier

unread,
Feb 16, 2008, 4:53:17 PM2/16/08
to Django users
On Feb 16, 3:41 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> Instead, you need to use 127.0.0.1 to force the connection to go via
> TCP/IP. I'm pretty sure, without having tested it, that Django will be
> fine with that (setting the HOST string to an IP address). We just pass
> that information straight through to the MySQLdb python wrapper, so
> whatever it accepts, we accept.

I'll try that, thanks.

Mike
Reply all
Reply to author
Forward
0 new messages