0

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

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 at 15:51
  • Is the socket present? Do you have permissions to access it? – Tomasz Sep 8 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 at 19:00
  • But do you have access to it as www-data (or whoever the server runs as)? – Tomasz Sep 8 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 at 2:24

Your Answer

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

Browse other questions tagged or ask your own question.