1

I'm trying to run a Perl script that connects to a remote MySQL database. I have MySQL installed locally on OSX via Homebrew.

This is the error:

DBI connect('database connection details') failed: SSL connection error: error:00000001:lib(0):func(0):reason(1)

How can I resolve this error, or get Perl to ignore SSL?

I've tried adding mysql_ssl=0, but the error still occurs.

Code:

# PERL MYSQL CONNECT()
$dbh = DBI->connect("DBI:mysql:database=$db;host=$host", $user, $password, {RaiseError => 1});
$dbh->{'mysql_enable_utf8'} = 1;
$dbh->{'mysql_ssl'} = 0;

1 Answer 1

1

mysql_ssl is not a handle attribute. If you try to use it like one, it's ignored, which you can see by turning on tracing:

use strict;
use warnings;

use DBI;

DBI->trace('1|CON');

my $dsn = 'DBI:mysql:test';
my $dbh = DBI->connect($dsn, 'foo', '', {
    PrintError => 0,
    RaiseError => 1,
    mysql_ssl  => 0  # equivalent to $dbh->{mysql_ssl} = 0
});

Output:

    DBI 1.627-ithread default trace level set to 0x200/1 (pid 30834 pi 1d0e010) at db line 8
    -> DBI->connect(DBI:mysql:test, foo, ****, HASH(0x1d3b550))
    -> DBI->install_driver(mysql) for linux perl=5.016003 pid=30834 ruid=12011 euid=12011
       install_driver: DBD::mysql version 4.023 loaded from /usr/lib64/perl5/vendor_perl/DBD/mysql.pm
    <- install_driver= DBI::dr=HASH(0x1e33a10)
    !! warn: 0 CLEARED by call to connect method
    -> connect for DBD::mysql::dr (DBI::dr=HASH(0x1e33a10)~0x1e33bf0 'test' 'foo' **** HASH(0x1e4d808)) thr#1d0e010
    <- connect= ( DBI::db=HASH(0x1f65fe0) ) [1 items] at DBI.pm line 670
    <- STORE('RaiseError', 1)= ( 1 ) [1 items] at DBI.pm line 722
    <- STORE('PrintError', 0)= ( 1 ) [1 items] at DBI.pm line 722
    <- STORE('AutoCommit', 1)= ( 1 ) [1 items] at DBI.pm line 722
    <- STORE('Username', 'foo')= ( 1 ) [1 items] at DBI.pm line 725
$h->{'mysql_ssl'}=0 ignored for invalid driver-specific attribute

Instead, add it to the DSN:

my $dsn = 'DBI:mysql:test;mysql_ssl=0';
my $dbh = DBI->connect($dsn, 'foo', '', {
    PrintError => 0,
    RaiseError => 1
});

Depending on the server configuration, you may still have issues (like if the server is configured to require SSL).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.