Ubuntu 20.04 - Perl DBI looking for mysqld.sock in the wrong place

fcmed

Verified User
Joined
Nov 16, 2016
Messages
7
I'm moving from Centos 7 to Ubuntu 20.04 and installed DA on Ubuntu 20.04

I have domains that have perl .cgi script files that connect to a Maria database with Perl's DBI modules.

When running a perl script that makes a connection to the database, (with DBI) the connection to the database fails with the following:
Cannot connect to MySQL server: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

/var/run/mysqld/mysqld.sock

does not exist but is actually here:
/usr/local/mysql/data/mysql.sock

The only solution to this problem that has worked for me so far was to create a symlink. For example:
/usr/bin/ln -s /usr/local/mysql/data/mysql.sock /var/run/mysqld/mysqld.sock

This works, but if you restart the mysql server or reboot the server the fix is 'no more'. (Not a desirable fix)

I have also tried editing /etc/my.cnf and specified:
socket=/usr/local/mysql/data/mysql.sock
but this has no effect. This is probably because:
/etc/systemd/system/mysqld.service has the following in it:
ExecStart=/usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/mysqld.pid --socket=/usr/local/mysql/data/mysql.sock

If I understand correctly making changes to mysqld.service would not work because DA would overwrite the changes when an update takes place.

Does anybody have a better solution to solving this other than using a symlink?

BTW: phpMyAdmin is working perfectly. It only seems to be Perl's DBI that has this problem of looking for mysqld.sock in the wrong place.

Thanks
 
The best solution I could get going was to specify 127.0.0.1 instead of localhost when doing the DBI database connection from the scripts themselves. localhost uses the mysql.sock file for the connection and 127.0.0.1 uses the IP address for the connection.

For example:
my $dbh =DBI>connect("dbi:mysql:database=some_db;host=127.0.0.1;port=3306","some_user","some_password", {'RaiseError' => 1});

In the mean time I also tried Debian 10 with DirectAdmin and had more or less the same issues as described in my post above. (Perhaps it is my hardware?? Who knows??) Not sure if there is an overhead when doing the connection with TCP on the IP address because connecting to the sock file will probably have less of an overhead? (be faster?) - (I have web sites with huge traffic.) Would still like to have this issue solved though. :/
 
Last edited:
Back
Top