I'm building an application that connects to a remote MySQL server using DBD::mysql. The DSN used in the connection uses these options, among others:
- mysql_ssl_ca_file
- mysql_ssl_client_key
- mysql_client_cert
Normally, when using these options in a DSN, one gives a location to a path on the filesystem. I would rather store these options as scalars. However, this doesn't seem to work:
#!/usr/bin/env perl
use strict;
use DBI;
my $host = 'localhost';
my $port = '3306';
my $username = 'username';
my $password = '';
my $db = 'database';
my $SSL_CA_FILE_STRING = <<"SSLCA";
-----BEGIN CERTIFICATE-----
<snip>
-----END CERTIFICATE-----
SSLCA
my $SSL_CLIENT_CERT_STRING = <<"SSL_CLIENT_CERT";
-----BEGIN CERTIFICATE-----
<snip>
-----END CERTIFICATE-----
SSL_CLIENT_CERT
my $SSL_CLIENT_KEY_STRING = <<"SSL_CLIENT_KEY";
-----BEGIN PRIVATE KEY-----
<snip>
-----END PRIVATE KEY-----
SSL_CLIENT_KEY
open my $ca_file_location, '<', \$SSL_CA_FILE_STRING || die $!;
open my $cert_file_location, '<', \$SSL_CLIENT_CERT_STRING || die $!;
open my $key_file_location, , '<', \$SSL_CLIENT_KEY_STRING || die $!;
my $dsn = "dbi:mysql:database=$db;host=$host;port=$port;"
. "mysql_ssl=1;mysql_ssl_ca_file=$ca_file_location;"
. "mysql_ssl_client_key=$key_file_location;"
. "mysql_ssl_client_cert=$cert_file_location";
my $dbh = DBI->connect( $dsn, $username, $password)
. || die;
The same DSN works if I provide filesystem paths. Any suggestions?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.