I’ve (3) freshly installed mysql, (4) freshly installed Connector/C++ 8.0 X DevAPI, (5) did minimal configuration in my.cnf, (1) wrote a minimal C++ program, (2) build it, and after executing it gave the following output:
$ sudo bin/sql
[sudo] password for xxxxxx:
CDK Error: unexpected message
But when I use mysql it connects properly:
$ sudo mysql --socket /var/run/mysqld/mysqld.sock -u root
<…>
Server version: 8.0.22 MySQL Community Server – GPL
<…>
mysql>
In my imagination, my minimal C++ program is doing the same the mysql client application is doing, but apparently not. What am I doing wrong here?
Below are some details which have been referred to in my opening sentence.
(1) The minimal C++ program:
#include <iostream>
#include <stdexcept>
#include <mysqlx/xdevapi.h>
int main()
{
try
{
mysqlx::Session sess("mysqlx://root@%2Fvar%2Frun%2Fmysqld%2Fmysqld.sock");
}
catch(std::exception& e)
{
std::cerr << e.what() << std::endl;
}
}
(2) Build with:
g++ -std=gnu++17 -I/usr/include/mysql-cppconn-8 sql.cpp -lstdc++fs -lmysqlcppconn8 -o bin/sql
chmod u+x bin/sql
(3) I’ve installed mysql:
<download from https://dev.mysql.com/downloads/repo/apt/>
$ sudo dpkg -i ~/Downloads/mysql-apt-config_0.8.16-1_all.deb
$ sudo apt-get update
$ sudo apt-get install mysql-server
<leave pwd blank>
$ systemctl status mysql
<active (running)>
$ mysql -V
mysql Ver 8.0.22 for Linux on x86_64 (MySQL Community Server - GPL)
(4) Installed Connector/C++ 8.0 X DevAPI (when I recall correctly)
<download from https://dev.mysql.com/downloads/connector/cpp/>
<chose Ubuntu Linux>
<Chose Ubuntu Linux 20.04 (x86, 64-bit)
<downloaded libmysqlcppconn8-2_8.0.22-1ubuntu20.04_amd64.deb>
$ sudo dpkg -i ~/Downloads/libmysqlcppconn8-2_8.0.22-1ubuntu20.04_amd64.deb
$ sudo apt-get update
$ sudo apt-get install libmysqlcppconn8-2
<downloaded libmysqlcppconn8-2-dbgsym_8.0.22-1ubuntu20.04_amd64.deb>
$ sudo dpkg -i ~/Downloads/libmysqlcppconn8-2-dbgsym_8.0.22-1ubuntu20.04_amd64.deb
$ sudo apt-get update
$ sudo apt-get install libmysqlcppconn8-2-dbgsym
<downloaded libmysqlcppconn-dev_8.0.22-1ubuntu20.04_amd64.deb>
$ sudo dpkg -i ~/Downloads/libmysqlcppconn-dev_8.0.22-1ubuntu20.04_amd64.deb
$ sudo apt-get update
$ sudo apt-get install libmysqlcppconn-dev
<downloaded libmysqlcppconn7_8.0.22-1ubuntu20.04_amd64.deb>
$ sudo dpkg -i ~/Downloads/libmysqlcppconn7_8.0.22-1ubuntu20.04_amd64.deb
$ sudo apt-get update
$ sudo apt-get install libmysqlcppconn7
<downloaded libmysqlcppconn7-dbgsym_8.0.22-1ubuntu20.04_amd64.deb>
$ sudo dpkg -i ~/Downloads/libmysqlcppconn7-dbgsym_8.0.22-1ubuntu20.04_amd64.deb
$ sudo apt-get update
$ sudo apt-get install libmysqlcppconn7-dbgsym
(5) Configured my.cnf and added [client] and socket
$ sudo vi /etc/mysql/my.cnf
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
<…>
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
[client]
socket = /var/run/mysqld/mysqld.sock
<save>
$ systemctl stop mysql
$ systemctl start mysql
$ systemctl status mysql
<active (running)>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…