Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

DBI mysql connection broke suddenly

by jimr451 (Novice)
on Nov 09, 2022 at 20:53 UTC ( [id://11148073]=perlquestion: print w/replies, xml ) Need Help??

jimr451 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I've had perl scripts running on this server for over a year, and suddenly, midday today, I'm getting this error:

DBI connect('shop_gal','gallery',...) failed: Access denied for user ' +gallery'@'localhost' (using password: YES) at ./testDB.cgi line 3.


My DBD-MySQL version is 4.023-6.e17
Mariadb version is 10.2.44

uname -a = Linux xxx.abc.com 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Connections from a php script work with the same user and password. I'm working with tech support, but I'm not confident they will have anyone able to debug this. I can't guess what happened.

Any suggestions?

Replies are listed 'Best First'.
Re: DBI mysql connection broke suddenly
by Bod (Parson) on Nov 09, 2022 at 22:28 UTC

    According to the documentation:
    "The $data_source value must begin with "dbi:driver_name:". The driver_name specifies the driver that will be used to make the connection. (Letter case is significant.)"

    'shop_gal' does not conform with that specification.

    Here is the line of code from part of our database code:

    return DBI->connect("DBD:mysql:database=$db:host=localhost:3306", $Sit +e::Variables::env_db_user, $Site::Variables::env_db_pass);

Re: DBI mysql connection broke suddenly
by choroba (Cardinal) on Nov 09, 2022 at 21:37 UTC
    Crossposted to StackOverflow.

    It's considered polite to inform about crossposting to prevent people not attending both the sites from wasting their efforts hacking on a problem already solved at the other end of the internets.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: DBI mysql connection broke suddenly
by jimr451 (Novice) on Nov 10, 2022 at 12:50 UTC
    Hi all,

    Thanks for the suggestions. I just wanted to update where things stand, in case this happens to anyone else.

    When I changed from "localhost" to "127.0.0.1", things worked. This apparently causes DBI to use TCP/IP for the connection rather than the mysql.sock file socket.

    Permissions on that file seem to be fine, but I'm still troubleshooting why that's not working. However, that's not a perl problem. It's good to know this workaround, though.

    Jim

      It's a long shot (and not really Perl related), but localhost is defined in /etc/hosts with a line like this:

      127.0.0.1 localhost
      I'm wondering if that file was updated recently on your system, perhaps removing that definition. On my client's machine, it looks like that file hasn't been changed in a while (like, not since I set it up almost five years ago).
      -rw-r--r-- 1 root root 187 Feb 4 2018 /etc/hosts

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

        Right in principle, but wrong for this special case.

        Long ago, someone has decided that the hostname "localhost" is special for MySQL. It won't be resolved at all, instead it connects via a Unix socket on Unix and via shared memory on Windows. On Windows, the hostnames "." and "" are also special, they use a named pipe instead of shared memory. This is documented e.g. in https://dev.mysql.com/doc/refman/8.0/en/connecting.html, in DBD::mysql and in DBD::MariaDB. If you want to connect to the local machine via TCP/IP, you have to use "127.0.0.1" or "::1".

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11148073]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-18 20:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found