From 2f7c4d5ca940a05364a0e67afe5c0d10e7308972 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 23 Apr 2006 22:18:53 +0000 Subject: [PATCH] magic-removal: Fixed #1481 -- Added support for using alternate MySQL Unix sockets. Thanks, Geert Vanderkelen git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2736 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/mysql/base.py | 5 ++++- docs/settings.txt | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index cb29e8388d..e2d6cbfc5e 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -75,9 +75,12 @@ class DatabaseWrapper(local): 'user': settings.DATABASE_USER, 'db': settings.DATABASE_NAME, 'passwd': settings.DATABASE_PASSWORD, - 'host': settings.DATABASE_HOST, 'conv': django_conversions, } + if settings.DATABASE_HOST.startswith('/'): + kwargs['unix_socket'] = settings.DATABASE_HOST + else: + kwargs['host'] = settings.DATABASE_HOST if settings.DATABASE_PORT: kwargs['port'] = int(settings.DATABASE_PORT) self.connection = Database.connect(**kwargs) diff --git a/docs/settings.txt b/docs/settings.txt index 9bf49e9969..b90e3b9027 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -239,6 +239,14 @@ Default: ``''`` (Empty string) Which host to use when connecting to the database. An empty string means localhost. Not used with SQLite. +If this value starts with a forward slash (``'/'``) and you're using MySQL, +MySQL will connect via a Unix socket to the specified socket. For example:: + + DATABASE_HOST = '/var/run/mysql' + +If you're using MySQL and this value *doesn't* start with a forward slash, then +this value is assumed to be the host. + DATABASE_NAME -------------