http://qs321.pair.com?node_id=1196476


in reply to Connection to mysql database fails when using SSL

Try this out and see it works better. The connect method is not documented to accept a DSN in that format.

#!/usr/bin/perl use strict; use warnings; use v5.10; use DBI; say "Perl MySQL Connect Demo"; my $db = 'db'; # or whatever it really is my $server = 'server'; # ditto my $dsn = "DBI:mysql:database=$db;host=$server"; my $username = "user"; my $password = 'password'; my $dbh = DBI->connect($dsn,$username,$password);

See also DBD::mysql Class Methods for the full documentation on connect.

Update: You may also need to add in the port.

Update 2: You may need to set some MySQL specific variables in order to get a secure connection working.

... my $port = 12345; # whatever is should be my $dsn = "DBI:mysql:database=$db;host=$server;port=$port; mysql_ssl=1; mysql_ssl_client_key=/var/lib/ssl/client-key.pem; mysql_ssl_client_cert=/var/lib/ssl/client-cert.pem; mysql_ssl_ca_file=/var/lib/ssl/cacert.pem"; # Your paths may vary... ...
<code>

Replies are listed 'Best First'.
Re^2: Connection to mysql database fails when using SSL
by wthebutcher (Initiate) on Aug 03, 2017 at 13:39 UTC
    Hi Mr. Muskrat, thank you for your response...it's been really helpful trying to debug what's going on. The thing is...I don't even want to use SSL to connect, as the connection will manage data that is neither relevant nor important (it's one of the tools percona provides to perform some checks over the data, but I tracked the issue to the connection itself rather than the tool, as I was able to reproduce the error creating that simple connection script). I tried specifying mysql_ssl=0 at the dsn, with no luck. I can connect to the server using mysql client without SSL, but couldn't get it to work with perl. Perl version is v5.22.1 built for x86_64-linux-gnu-thread-multi, and we first started having this kind of issues when we moved from Ubuntu 12.04 to Ubunt 16.04 Any Ideas?