我正在尝试使用嵌入式MariaDB(即不连接到正在运行的服务器)设置,但我没有得到任何我发现的工作示例.
我最近的例子来自这篇文章/sf/ask/17360801/
当应用程序运行时,它会生成:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
文档https://mariadb.com/kb/en/library/embedded-mariadb-interface/对此没什么帮助.
为方便起见,StackOverflow帖子中的代码是:
#include#include int main(int argc, char **argv) { static char *server_options[] = { "mysql_test", // An unused string "--datadir=/tmp/mysql_embedded_data", // Your data dir NULL }; int num_elements = (sizeof(server_options) / sizeof(char *)) - 1; static char *server_groups[] = { "libmysqld_server", "libmysqld_client", NULL }; // Init MySQL lib and connection mysql_library_init(num_elements, server_options, server_groups); MYSQL *con = mysql_init(NULL); if (con == NULL) { fprintf(stderr, "%s\n", mysql_error(con)); exit(1); } mysql_options(con, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client"); mysql_options(con, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL); // Connect to no host/port -> Embedded mode if (mysql_real_connect(con, NULL, NULL, NULL, NULL, 0, NULL, 0) == NULL) { fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } // Create a sample empty DB, named "aNewDatabase" if (mysql_query(con, "CREATE DATABASE aNewDatabase")) { fprintf(stderr, "%s\n", mysql_error(con)); mysql_close(con); exit(1); } // Close connection mysql_close(con); exit(0); }
我粗略地看了一眼https://github.com/MariaDB/server,但不知道在哪里看......或者实际上我在寻找什么.如何获得嵌入式mariadb?我在Mac OS High Sierra上运行,MariaDB安装了brew install mariadb --with-embedded
.
更新:
我很确定我正在链接到正确的lib.
ls /usr/local/lib | grep maria
FIND_LIBRARY(mariadb mariadb) MESSAGE(FATAL_ERROR "BOOM ${mariadb}")
输出是:
BOOM /usr/local/lib/libmariadb.dylib
更新2
我现在链接到以下内容.请注意,我开始只使用libmysqld并添加库,直到所有链接错误消失.这里的麻烦是我可能没有所有正确的库或版本.
TARGET_LINK_LIBRARIES(sql_fn /usr/local/lib/libmysqld.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/openssl/lib/libcrypto.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/openssl/lib/libssl.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/bzip2/lib/libbz2.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/lib/liblz4.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/zlib/lib/libz.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/opt/xz/lib/liblzma.a) TARGET_LINK_LIBRARIES(sql_fn /usr/local/lib/libsnappy.a)
它现在编译但退出代码6
Process finished with exit code 6
看看/sf/ask/17360801/,如果它指向相同的东西/仍然是真的那么退出代码6意味着EX_ILLEGAL_TABLE 6
,不幸的是我不知道会是什么表.mysql_test
传入的和datadir字符串是有效的标识符/路径.