针对mariadb-connector-c构建python-mysqlclient

时间:2017-11-07 10:12:47

标签: python mariadb mysql-python libmysql

我正在尝试在Conda环境中针对python-mysqlclient编译mariadb-connector-c。这意味着安装前缀不是/usr/local,而是$HOME/conda/envs/test。我还想使用auth_gssapi_client.so插件。

两个包都构建,但import MySQLdb引发了以下异常:

Traceback (most recent call last):
  File "/opt/emsconda/conda-bld/env/test_tmp/run_test.py", line 2, in <module>
    import MySQLdb
  File "/opt/emsconda/conda-bld/env/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: libmariadb.so.3: cannot open shared object file: No such file or directory

原因是 mysqlclient 只搜索lib/但不搜索 lib/mariadb即使它配置了正确的路径并且成功 建成。我可以通过将*.so文件复制到lib/来解决此问题 通过创建一个符号链接),但是,它找不到GSSAPI插件...

我用这种方式构建 mariadb-connector-c 3.0.2

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Release ..
make
make install

我可以安装它并运行mariadb_config来提供此输出:

Copyright 2011-2015 MariaDB Corporation AB
Get compiler flags for using the MariaDB Connector/C.
Usage: /opt/emsconda/conda-bld/mysqlclient_1510048680472/_h_env/bin/mariadb_config [OPTIONS]
  --cflags        [-I/opt/emsconda/conda-bld/env/include/mariadb -I/opt/emsconda/conda-bld/env/include/mariadb/mysql]
  --include       [-I/opt/emsconda/conda-bld/env/include/mariadb -I/opt/emsconda/conda-bld/env/include/mariadb/mysql]
  --libs          [-L/opt/emsconda/conda-bld/env/lib/mariadb/ -lmariadb -lpthread -ldl -lm -lssl -lcrypto]
  --libs_r        [-L/opt/emsconda/conda-bld/env/lib/mariadb/ -lmariadb -lpthread -ldl -lm -lssl -lcrypto]
  --libs_sys      [-lpthread -ldl -lm -lssl -lcrypto]
  --version       [10.2.6]
  --socket        [/tmp/mysql.sock]
  --port          [3306]
  --plugindir     [/opt/emsconda/conda-bld/env/lib/mariadb/plugin]
  --tlsinfo       [OpenSSL 1.0.2k]

然后我用这种方式构建 python-mysqlclient 1.3.12

MYSQL_CONFIG="$PREFIX/bin/mariadb_config"
echo "mysql_config = $PREFIX/bin/mariadb_config" >> site.cfg
$PYTHON -m pip install -I --no-deps .

此问题有两种可能的解决方案:

  1. 配置 mariadb-connector-c 直接将其内容放入lib/ - 我还没有找到有关如何执行此操作的文档。

  2. python-mysqlclient 尊重mariadb_config返回的路径 - 如何?

1 个答案:

答案 0 :(得分:0)

您必须将gssapi内容静态链接到 mariadb-connector-c ,Python mysqlclient 才能正常工作。

这是如何构建 mariadb-connector-c:

mkdir build
cd build

cmake \
    -DCMAKE_INSTALL_PREFIX=$PREFIX \
    -DINSTALL_LIBDIR=lib \
    -DINSTALL_PLUGINDIR=lib/plugin \
    -DWITH_MYSQLCOMPAT=ON \
    -DAUTH_GSSAPI=STATIC \
    -DCMAKE_BUILD_TYPE=Release \
    ..

make
make install

# WITH_MYSQLCOMPAT only creates links for the libs, not for the binary:
cd $PREFIX/bin
ln -s mariadb_config mysql_config