MySQL agent does not work if using non-standard socket
My server's socket is /tmp/mysql.sock, Perl DBI:MySQL is hard coded to '/var/lib/mysql/mysql.sock'.
Rather than create a symlink, I modified line 69 in DataGetter/Applications/MySQL.pm, adding my specific socket.
my $dbh = DBI->connect_cached( "DBI:mysql:host=localhost;mysql_socket=/tmp/mysql.sock;", $creds->{username}, $creds->{password} ) or do {
It would be better if I could provide a non-default socket in the Longview MySQL configuration file.
Just a thought on this from a sysadmin perspective... MySQL servers usually contain the MySQL client for management and have their root unix users configured with the root MySQL credentials and connection information under /root/.my.cnf. Could this root MySQL client be used to dynamically determine the socket location if no defaults exist e.g. /tmp/mysql.sock, /var/lib/mysql/mysql.sock?
From what I've read, DBD:Perl uses /var/lib/mysql/mysql.sock if you don't specify otherwise. It does not look for /etc/my.cnf to figure out the socket. For now, patching the MySQL.pm file in Longview works for me.
The best solution would be to just use 'mysql_read_default_group' to tell libmysqlclient to read the my.cnf file for settings, which can be done with the following DBI connection string:
DBI:mysql:mysql_read_default_group=client
I agree that anything is better than me having to patch the Longview code myself. It seems appropriate to me that the app should figure out the socket from the usual my.cnf locations and/or allow me to specify the socket in the Longview mysql config file.
Ideally host config var could be supported in /etc/linode/longview.d/MySQL.conf
I run my infra on docker and needed to make the following change to get Longview to pick up data:
sed -i -e '/s/DBI:mysql:host=localhost/DBI:mysql:host=0.0.0.0/g' /opt/linode/longview/Linode/Longview/DataGetter/Applications/MySQL.pm
There is no shared socket for docker, so localhost (a special alias for the socket) doesn't work
Same problem, should i correct like this ?
sed -i -e '/s/DBI:mysql:host=localhost/DBI:mysql:mysql_read_default_group=client:host=localhost/g' /opt/linode/longview/Linode/Longview/DataGetter/Applications/MySQL.pm
I think it'd be neat if it used the my.cnf config for this. Would be nice if it checked a longview group first before checking client so you can give longview it's own thing. Or at the very least have it so you can specify a config file to use (ala defaults-extra-file)