I’m using perl 5.22.0 and DBD::mysql version 4.041 installed with -ssl option. I have successfully connected to remote mysql from linux shell using CA file:
mysql -h database_host -u username --password=password --ssl-ca= /path +_to_CA_file/ca-cert.pem
Only CA file is used for connection to database, X509 CA cert and X509 CA key are not required.I’m trying to connect using following command:
my $dbhost = "database_host"; my $dbuser = "username"; my $dbpw = "password"; my $cafile = "/path_to_CA_file/ca-cert.pem"; #my $key = undef; #my $cert = undef; my $dbname = "dbname"; my $dbtable = "dbtable"; my $dbh = DBI->connect("DBI:mysql:database=$dbname;host=$dbhost;mysql_ +ssl=1;mysql_ssl_ca_file=$cafile","$dbuser", "$dbpw",{'RaiseError' => +1}) or die "Error in connecting to database";
And I have SSL connection error 2026
-> DBI->connect(DBI:mysql:database=dbname;host=database_host;mysql +_ssl=1;mysql_ssl_ca_file=/path_to_CA_file/ca-cert.pem, username, **** +, HASH(0x7c9080)) -> DBI->install_driver(mysql) for linux perl=5.022000 pid=20099 ru +id=83598 euid=83598 install_driver: DBD::mysql version 4.041 loaded from /app/vbuil +d/SLED11-x86_64/perl/5.22-addons-secure_mysql/x86_64-linux-thread-mul +ti/DBD/mysql.pm New 'DBI::dr' (for DBD::mysql::dr, parent='', id=undef) dbih_setup_handle(DBI::dr=HASH(0x10c5738)=>DBI::dr=HASH(0x10bbe80) +, DBD::mysql::dr, 0, Null!) dbih_make_com(Null!, 0, DBD::mysql::dr, 152, 0) thr#7c6010 dbih_setup_attrib(DBI::dr=HASH(0x10bbe80), Err, Null!) SCALAR(0xf9 +a938) (already defined) dbih_setup_attrib(DBI::dr=HASH(0x10bbe80), State, Null!) SCALAR(0x +adc370) (already defined) dbih_setup_attrib(DBI::dr=HASH(0x10bbe80), Errstr, Null!) SCALAR(0 +xfab6c8) (already defined) dbih_setup_attrib(DBI::dr=HASH(0x10bbe80), TraceLevel, Null!) 0 (a +lready defined) dbih_setup_attrib(DBI::dr=HASH(0x10bbe80), FetchHashKeyName, Null! +) 'NAME' (already defined) install_method DBI::db::mysql_fd install_method DBI::db::mysql_async_result install_method DBI::db::mysql_async_ready install_method DBI::st::mysql_async_result install_method DBI::st::mysql_async_ready <- install_driver= DBI::dr=HASH(0x10c5738) >> connect DISPATCH (DBI::dr=HASH(0x10c5738) rc2/3 @5 g2 ima80 +01 pid#20099) at /app/vbuild/SLED11-x86_64/perl/5.22-addons-secure_my +sql/x86_64-linux-thread-multi/DBI.pm line 684 !! The warn '0' was CLEARED by call to connect method -> connect for DBD::mysql::dr (DBI::dr=HASH(0x10c5738)~0x10bbe80 ' +database=dbname;host=database_host;mysql_ssl=1;mysql_ssl_ca_file=/pat +h_to_CA_file/ca-cert.pem' 'username' **** HASH(0xa63c98)) thr#7c6010 New 'DBI::db' (for DBD::mysql::db, parent=DBI::dr=HASH(0x10bbe80), + id=HASH(0x10ce280)) dbih_setup_handle(DBI::db=HASH(0x10ce5e0)=>DBI::db=HASH(0x10ce370) +, DBD::mysql::db, adc628, HASH(0x10ce280)) dbih_make_com(DBI::dr=HASH(0x10bbe80), 1012500, DBD::mysql::db, 19 +2, 10ce298) thr#7c6010 dbih_setup_attrib(DBI::db=HASH(0x10ce370), Err, DBI::dr=HASH(0x10b +be80)) SCALAR(0xadc850) (already defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), State, DBI::dr=HASH(0x1 +0bbe80)) SCALAR(0xadc8b0) (already defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), Errstr, DBI::dr=HASH(0x +10bbe80)) SCALAR(0xadc880) (already defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), TraceLevel, DBI::dr=HAS +H(0x10bbe80)) 0 (already defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), FetchHashKeyName, DBI:: +dr=HASH(0x10bbe80)) 'NAME' (already defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), HandleSetErr, DBI::dr=H +ASH(0x10bbe80)) undef (not defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), HandleError, DBI::dr=HA +SH(0x10bbe80)) undef (not defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), ReadOnly, DBI::dr=HASH( +0x10bbe80)) undef (not defined) dbih_setup_attrib(DBI::db=HASH(0x10ce370), Profile, DBI::dr=HASH(0 +x10bbe80)) undef (not defined) imp_dbh->connect: dsn = database=dbname;host=database_host;mysql_ssl=1 +;mysql_ssl_ca_file=/path_to_CA_file/ca-cert.pem, uid = username, pwd += password imp_dbh->my_login : dbname = dbname, uid = username, pwd = password,ho +st = database_host, port = NULL imp_dbh->mysql_dr_connect: host = |database_host|, port = 0, uid = use +rname, pwd = password imp_dbh->bind_type_guessing: 0 imp_dbh->use_server_side_prepare: 0 imp_dbh->disable_fallback_for_server_prepare: 0 imp_dbh->mysql_dr_connect: client_flags = 2050 imp_dbh->mysql_dr_connect: <- --> do_error SSL connection error error 2026 recorded: SSL connection error <-- do_error
I didn't find in DBD::mysql readme which flag are mandatory bellow you can find DBD:myql attributes/flags description:
mysql_ssl
A true value turns on the CLIENT_SSL flag when connecting to the MySQL database:
mysql_ssl=1 --------> specified in command
This means that your communication with the server will be encrypted.
Please note that this can only work if you enabled SSL when compiling DBD::mysql; this is the default starting version 4.034. See DBD::mysql::INSTALL for more details.
If you turn mysql_ssl on, you might also wish to use the following flags:
mysql_ssl_client_key ----> not required for connection but I'm not sure is it mandatoray in perl
mysql_ssl_client_cert ----> not required for connection but I'm not sure is it mandatoray in perl
mysql_ssl_ca_file --------> specified in command
mysql_ssl_ca_path
mysql_ssl_cipher
These are used to specify the respective parameters of a call to mysql_ssl_set, if mysql_ssl is turned on.
Could you please help me in finding solution?

In reply to DBI problem connecting MYSQL using secure connection by ddrazin

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.