带有MySQL的Perl模块DBI抛出“记录的错误2026:SSL连接错误:协议版本不匹配”

时间:2016-12-01 15:47:19

标签: mysql perl ssl

在你抱怨之前问过这个问题之前:我不想建立一个ssl连接。

我只是尝试从我的客户端(Ubuntu 16.04)连接:

  

mysql Ver 15.1 Distrib 10.0.27-MariaDB

到较旧的MySQL服务器(在solaris上运行):

  

5.5.10-log MySQL社区服务器(GPL)

with perl。

我试图显式禁用mysql_ssl,但它似乎什么都没改变。

当我将下面的samme perl代码连接到具有实际版本的另一个MariaDB时,没有错误。 当我在命令行上使用MySQL-Client连接到旧的MySQL-Server时,没有错误。

服务器变量设置如下:

MySQL [(none)]> show variables like '%ssl%';
+---------------+--------------------------------+
| Variable_name | Value                          |
+---------------+--------------------------------+
| have_openssl  | YES                            |
| have_ssl      | YES                            |
| ssl_ca        | /etc/mysql/ssl/ca-cert.pem     |
| ssl_capath    |                                |
| ssl_cert      | /etc/mysql/ssl/server-cert.pem |
| ssl_cipher    |                                |
| ssl_key       | /etc/mysql/ssl/server-key.pem  |
+---------------+--------------------------------+

我的perl代码如下所示:

$ perl -e '
use DBI;
DBI->trace("15|CON");
my $dbh = DBI->connect("DBI:mysql:host=my_dbhost;database=test;", "test", "test", 
  { 
    PrintError => 1, 
    RaiseError => 1, 
    mysql_ssl => 0,
    mysql_skip_secure_auth => 1 
  });
$dbh->disconnect();'

这是调试级别15输出:

    DBI 1.634-ithread default trace level set to 0x200/15 (pid 11328 pi ee1010) at -e line 1
    -> DBI->connect(DBI:mysql:host=my_dbhost;database=test;, test, ****, HASH(0xee3f30))
    -> DBI->install_driver(mysql) for linux perl=5.022001 pid=11328 ruid=10000 euid=10000
       install_driver: DBD::mysql version 4.033 loaded from /usr/lib/x86_64-linux-gnu/perl5/5.22/DBD/mysql.pm
    New 'DBI::dr' (for DBD::mysql::dr, parent='', id=undef)
    dbih_setup_handle(DBI::dr=HASH(0x11e6848)=>DBI::dr=HASH(0xf184e8), DBD::mysql::dr, 0, Null!)
    dbih_make_com(Null!, 0, DBD::mysql::dr, 152, 0) thr#ee1010
    dbih_setup_attrib(DBI::dr=HASH(0xf184e8), Err, Null!) SCALAR(0x1016f28) (already defined)
    dbih_setup_attrib(DBI::dr=HASH(0xf184e8), State, Null!) SCALAR(0x10db678) (already defined)
    dbih_setup_attrib(DBI::dr=HASH(0xf184e8), Errstr, Null!) SCALAR(0x103c648) (already defined)
    dbih_setup_attrib(DBI::dr=HASH(0xf184e8), TraceLevel, Null!) 0 (already defined)
    dbih_setup_attrib(DBI::dr=HASH(0xf184e8), 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(0x11e6848)
    >> connect     DISPATCH (DBI::dr=HASH(0x11e6848) rc2/3 @5 g2 ima8001 pid#11328) at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBI.pm line 683
    !! The warn '0' was CLEARED by call to connect method
    -> connect for DBD::mysql::dr (DBI::dr=HASH(0x11e6848)~0xf184e8 'host=my_dbhost;database=test;' 'test' **** HASH(0x106d978)) thr#ee1010
    New 'DBI::db' (for DBD::mysql::db, parent=DBI::dr=HASH(0xf184e8), id=HASH(0x12164b8))
    dbih_setup_handle(DBI::db=HASH(0x1216338)=>DBI::db=HASH(0x121ce50), DBD::mysql::db, 10db930, HASH(0x12164b8))
    dbih_make_com(DBI::dr=HASH(0xf184e8), f0fd90, DBD::mysql::db, 192, 121cd78) thr#ee1010
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), Err, DBI::dr=HASH(0xf184e8)) SCALAR(0x10f2d70) (already defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), State, DBI::dr=HASH(0xf184e8)) SCALAR(0x10f2dd0) (already defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), Errstr, DBI::dr=HASH(0xf184e8)) SCALAR(0x10f2da0) (already defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), TraceLevel, DBI::dr=HASH(0xf184e8)) 0 (already defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), FetchHashKeyName, DBI::dr=HASH(0xf184e8)) 'NAME' (already defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), HandleSetErr, DBI::dr=HASH(0xf184e8)) undef (not defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), HandleError, DBI::dr=HASH(0xf184e8)) undef (not defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), ReadOnly, DBI::dr=HASH(0xf184e8)) undef (not defined)
    dbih_setup_attrib(DBI::db=HASH(0x121ce50), Profile, DBI::dr=HASH(0xf184e8)) undef (not defined)
imp_dbh->connect: dsn = host=my_dbhost;database=test;, uid = test, pwd = test
imp_dbh->my_login : dbname = test, uid = test, pwd = test,host = my_dbhost, port = NULL
imp_dbh->mysql_dr_connect: host = |my_dbhost|, port = 0, uid = test, pwd = test
imp_dbh->mysql_dr_connect: Skipping secure auth
imp_dbh->bind_type_guessing: 0
imp_dbh->use_server_side_prepare: 0
imp_dbh->mysql_dr_connect: client_flags = 2
imp_dbh->mysql_dr_connect: <-       --> do_error
SSL connection error: protocol version mismatch error 2026 recorded: SSL connection error: protocol version mismatch
        <-- do_error
    >> DESTROY     DISPATCH (DBI::db=HASH(0x1216338) rc1/1 @1 g2 ima10004 pid#11328) at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBD/mysql.pm line 163 via  at -e line 1
    <> DESTROY(DBI::db=HASH(0x1216338)) ignored for outer handle (inner DBI::db=HASH(0x121ce50) has ref cnt 2)
    >> DESTROY     DISPATCH (DBI::db=HASH(0x121ce50) rc1/1 @1 g2 ima10004 pid#11328) at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBI.pm line 683 via  at -e line 1
    -> DESTROY for DBD::mysql::db (DBI::db=HASH(0x121ce50)~INNER) thr#ee1010
         DESTROY for DBI::db=HASH(0x121ce50) ignored - handle not initialised
       ERROR: 2026 'SSL connection error: protocol version mismatch' (err#0)
    <- DESTROY= ( undef ) [1 items] at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBI.pm line 683 via  at -e line 1
    DESTROY (dbih_clearcom) (dbh 0x121ce50, com 0x123c3b0, imp DBD::mysql::db):
       FLAGS 0x100211: COMSET Warn PrintWarn AutoCommit 
       ERR 2026
       ERRSTR 'SSL connection error: protocol version mismatch'
       PARENT DBI::dr=HASH(0xf184e8)
       KIDS 0 (0 Active)
       IMP_DATA HASH(0x12164b8)
    dbih_clearcom 0x121ce50 (com 0x123c3b0, type 2) done.

    !! ERROR: 2026 'SSL connection error: protocol version mismatch' (err#0)
    <- connect= ( undef ) [1 items] at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBI.pm line 683
    -> $DBI::errstr (&) FETCH from lasth=HASH
    >> DBD::mysql::dr::errstr
    <- $DBI::errstr= 'SSL connection error: protocol version mismatch'
       DBI connect('host=my_dbhost;database=test;','test',...) failed: SSL connection error: protocol version mismatch
DBI connect('host=my_dbhost;database=test;','test',...) failed: SSL connection error: protocol version mismatch at -e line 1.
    -- DBI::END ($@: , $!: )
    >> disconnect_all DISPATCH (DBI::dr=HASH(0x11e6848) rc1/3 @1 g2 ima801 pid#11328) at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBI.pm line 762 via  at /usr/share/perl/5.22/Carp.pm line 166
    !! The ERROR '2026' was CLEARED by call to disconnect_all method
    -> disconnect_all for DBD::mysql::dr (DBI::dr=HASH(0x11e6848)~0xf184e8) thr#ee1010
    <- disconnect_all= ( ) [0 items] (not implemented) at /usr/lib/x86_64-linux-gnu/perl5/5.22/DBI.pm line 762 via  at /usr/share/perl/5.22/Carp.pm line 166
!   >> DESTROY     DISPATCH (DBI::dr=HASH(0xf184e8) rc1/1 @1 g2 ima10004 pid#11328) during global destruction
!   -> DESTROY in DBD::_::common for DBD::mysql::dr (DBI::dr=HASH(0xf184e8)~INNER) thr#ee1010
!   <- DESTROY= ( undef ) [1 items] during global destruction
    DESTROY (dbih_clearcom) (drh 0x11e6848, com 0xf0fd90, imp global destruction):
       FLAGS 0x100215: COMSET Active Warn PrintWarn AutoCommit 
       PARENT undef
       KIDS 0 (0 Active)
    dbih_clearcom 0x11e6848 (com 0xf0fd90, type 1) done.

!   >> DESTROY     DISPATCH (DBI::dr=HASH(0x11e6848) rc1/1 @1 g2 ima10004 pid#11328) during global destruction
!   <> DESTROY for DBI::dr=HASH(0x11e6848) ignored (inner handle gone)

perl使用的库:

$ ldd /usr/lib/x86_64-linux-gnu/perl5/5.22/auto/DBD/mysql/mysql.so | grep libmysqlclient
    libmysqlclient.so.20 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 (0x00007f3fbef0f000)

$ dpkg -S libmysqlclient.so.20
libmysqlclient20:amd64: /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
libmysqlclient20:amd64: /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20.3.3

$ dpkg -l libmysqlclient20 
libmysqlclient20:amd64          5.7.16-0ubuntu0.16.0 amd64         MySQL database client library

如何在连接上真正禁用ssl? 提前谢谢!

1 个答案:

答案 0 :(得分:0)

解决方法似乎是编译DBD :: mysql而不是预先编译Ubuntu。我在我的例子中使用了mariadb库。 我在安装最少的Ubuntu 16.04上所做的是:

$ sudo apt install libmariadb-client-lgpl-dev libdbi-perl gcc
$ sudo ln -s /usr/bin/mariadb_config /usr/bin/mysql_config
$ sudo perl -MCPAN -eshell
cpan[1]> install DBD::mysql

之后我从上面打来的perl工作正常。我将在ubuntu上提交一个错误。