简体   繁体   English

c++ 无法连接到 mysql

[英]c++ failed to connect to mysql

I get the following error message when I connect to mysql:连接到 mysql 时收到以下错误消息:

CDK Error: unexpected message

client is Ubuntu 19.04 server is Ubuntu 18.04.1 LTS客户端是 Ubuntu 19.04 服务器是 Ubuntu 18.04.1 LTS

The client library is: libmysqlcppconn-dev/bionic,now 1.1.9-1 amd64 [installed]客户端库是:libmysqlcppconn-dev/bionic,now 1.1.9-1 amd64 [已安装]

mysql server is version: 5.7.27-0 mysql 服务器版本:5.7.27-0

I can connect via the mysql command line client using the same credentials.我可以使用相同的凭据通过 mysql 命令行客户端进行连接。


using namespace mysqlx;

int main(int argc, char **argv)
{
    Session s
    (
        SessionOption::HOST, "11.11.11.11"
        ,SessionOption::PORT, 3306
        ,SessionOption::USER, "xxx"
        ,SessionOption::PWD, "xxx"
        ,SessionOption::DB, "xxx"
    );
}

OUTPUT: OUTPUT:

mysqltest 
terminate called after throwing an instance of 'mysqlx::abi2::r0::Error'
  what():  CDK Error: Broken pipe (generic:32)
Aborted (core dumped)

Today I had the same problem.今天我遇到了同样的问题。 Solution:解决方案:

  1. Using command line, log in to your mysql server using the following command:使用命令行,使用以下命令登录到您的 mysql 服务器:
mysql -u user -p -e "SHOW plugins"
  1. Make sure the plugin mysqlx is actived.确保插件mysqlx已激活。
+----------------------------+----------+--------------------+---------+---------+
| Name                       | Status   | Type               | Library | License |
+----------------------------+----------+--------------------+---------+---------+
...
| mysqlx                     | ACTIVE   | DAEMON             | NULL    | GPL     |

In my case it wasn't even on the list.就我而言,它甚至不在名单上。

More information: https://dev.mysql.com/doc/refman/8.0/en/x-plugin-checking-installation.html更多信息: https://dev.mysql.com/doc/refman/8.0/en/x-plugin-checking-installation.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM