Hello wthebutcher,

Welcome to the Monastery. I do not know if you problem is resolved so I would like to add something minor.

I would agree with fellow monk Mr. Muskrat on the connect call but also I would use DBI/RaiseError on your connect call to capture any errors to see at least the possible reason of your error.

From the documentation:

The RaiseError attribute can be used to force errors to raise exceptio +ns rather than simply return error codes in the normal way.

Sample of code:

#!/usr/bin/perl use DBI; use v5.10; use strict; use warnings; use feature 'say'; use Config::Simple; my %config = (); my $path = 'conf.ini'; sub mysql_con { Config::Simple->import_from("".$path."", \%config) or die Config::Simple->error(); my $dbh = DBI->connect("dbi:mysql::".$config{'MySQL.host'}.":".$co +nfig{'MySQL.port'}."", "".$config{'MySQL.user'}."", "".$config{'MySQL.pass'}."", { 'PrintError' => 1, 'RaiseError' => 1 , 'AutoInactiveD +estroy' => 1 } ) or die "Could not connect to ". $config{'MySQL.host'} .": ". $DB +I::errstr ."\n"; my $databases = $dbh->do("SHOW DATABASES LIKE '".$config{'MySQL.db +'}."'") or die "Error: " .dbh->errstr. "\n"; $dbh->disconnect() or warn "Error disconnecting: $DBI::errstr\n"; if ($databases eq 1) { return "Database: ". $config{'MySQL.db'} . " exists not creating: ". $config{'MySQL.db'} .""; } return "Database: ". $config{'MySQL.db'} . " does not exist create: ". $config{'MySQL.db'} .""; } say mysql_con();

I also use the Config::Simple module as I prefer to when I have multiple scripts connecting to multiple databases. Sample of config file (conf.ini) bellow:

[MySQL] user=user pass=password host=localhost port=3306 db=PerlMonks

Update: Adding ssl certification to connect:

#!/usr/bin/perl use DBI; use v5.10; use strict; use warnings; use feature 'say'; use Config::Simple; my %config = (); my $path = 'conf.ini'; sub mysql_con { Config::Simple->import_from("".$path."", \%config) or die Config::Simple->error(); my $dbh = DBI->connect("dbi:mysql::".$config{'MySQL.host'}.":".$co +nfig{'MySQL.port'}.", mysql_ssl=1; mysql_ssl_client_key=/etc/mysql/certs/client-key.pem; mysql_ssl_client_cert=/etc/mysql/certs/client-cert.pem; mysql_ssl_ca_file=/etc/mysql/certs/ca-cert.pem", $config{'MySQL.user'}, $config{'MySQL.pass'}, { 'PrintError' => 1, 'RaiseError' => 1 , 'AutoInactiveD +estroy' => 1 } ) or die "Could not connect to ". $config{'MySQL.host'} .": ". $DB +I::errstr ."\n"; my $databases = $dbh->do("SHOW DATABASES LIKE '".$config{'MySQL.db +'}."'") or die "Error: " .dbh->errstr. "\n"; $dbh->disconnect() or warn "Error disconnecting: $DBI::errstr\n"; if ($databases eq 1) { return "Database: ". $config{'MySQL.db'} . " exists not creating: ". $config{'MySQL.db'} .""; } return "Database: ". $config{'MySQL.db'} . " does not exist create: ". $config{'MySQL.db'} .""; } say mysql_con(); __END__ $ perl mysql.pl Database: PerlMonks exists not creating: PerlMonks

You can also read more about in similar question with examples DBI:mysql connection over SSL fails

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Connection to mysql database fails when using SSL by thanos1983
in thread Connection to mysql database fails when using SSL by wthebutcher

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.