Perl:连接到远程数据库SSL错误

时间:2016-01-08 11:52:14

标签: mysql perl ssl

我正在尝试运行连接到远程MySQL数据库的Perl脚本。我通过Homebrew在OSX上本地安装了MySQL。

这是错误:

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

如何解决此错误,或让Perl忽略SSL?

我尝试添加mysql_ssl = 0,但错误仍然存​​在。

代码:

# 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 个答案:

答案 0 :(得分:1)

mysql_ssl不是句柄属性。如果您尝试使用它,它会被忽略,您可以通过启用跟踪来查看:

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
});

输出:

    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

而是将其添加到DSN:

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

根据服务器配置的不同,您可能仍会遇到问题(例如,如果服务器配置为需要SSL)。