I'm migrating to new server hardware, which also means learning the idiosyncrasies of a new Linux distribution (Debian buster).

I've got a Perl CGI script which when run from the console runs, but fails to connect to MySQL with:

AH01215: DBI connect('my_db','my_db_user',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

Given it's running on the same hardware, so it'll be the same Perl install, etc. I'm at a loss as to why it's not working? I know back on Centos, SELinux could get in the way, but I don't believe Debian has this by default, but is there something similar that I'd need to do to allow child processes to make connections?

mysqladmin suggests that's the right place (i.e I'm not hitting this issue):

# mysqladmin version -p
Enter password:
mysqladmin  Ver 8.0.17 for Linux on i686 (Source distribution)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Server version          8.0.17
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /tmp/mysql.sock
Uptime:                 3 days 26 min 34 sec

Threads: 2  Questions: 74254  Slow queries: 0  Opens: 1042  Flush tables: 3  Open tables: 962  Queries per second avg: 0.284

And the socket clearly exists (as executing from console works)

$ ls -lF /tmp/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Sep  6 22:33 /tmp/mysql.sock=
  • OK, so why the anonymous downvote? After all, I've at least tried to verify from the console, but that just works :/ – Rowland Shaw Sep 8 '19 at 15:51
  • Is the socket present? Do you have permissions to access it? – user147505 Sep 8 '19 at 17:07
  • @Tomasz The socket is present and I have permissions to access it (after all, it works from the console) – Rowland Shaw Sep 8 '19 at 19:00
  • But do you have access to it as www-data (or whoever the server runs as)? – user147505 Sep 8 '19 at 19:33
  • 1
    root can always switch to any uid, even if have /bin/false or similar as a shell. e.g. su - www-data -s /bin/bash. – cas Sep 9 '19 at 2:24

Apache2 on Debian 9 and 10 is started from systemd. it has


in its definition. So processes started from the server don't have access to the regular /tmp and /var/tmp directories. Instead, they have their own directories.

You can either move the socket out of /tmp or start apache2 with


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.