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 -------------