php - 错误: wrong mysql library version or lib not found (when building PHP 7 with a custom built MySQL 8)

标签 php mysql docker

错误信息:

configure: error: wrong mysql library version or lib not found. Check config.log for more information.
The command '/bin/sh -c ./configure   --prefix=/usr/local/php/install   --with-apxs2=/usr/local/apache/bin/apxs   --with-config-file-path=/usr/local/php-7.3.2/   --enable-libgcc   --with-mysqli=/usr/local/mysql/install/bin/mysql_config   --with-pdo-mysql=/usr/local/mysql/install/   --with-zlib-dir=/usr   --with-jpeg-dir=/usr   --with-png-dir=/usr   --with-gd=/usr/local   --with-freetype-dir=/usr   --enable-ftp   --enable-xml   --enable-zip   --with-bz2   --enable-wddx   --without-pear   --enable-mbstring   --with-openssl   --with-curl   --enable-intl   && make   && make install   && make clean' returned a non-zero code: 1

由 Dockerfile 中的配置命令给出:

# Installing php

WORKDIR /usr/local/include
RUN ln -s /usr/include/x86_64-linux-gnu/curl curl

RUN apt-get update \
  && apt-get install -y \
  libxml2-dev libxslt-dev \
  libicu-dev \
  pkg-config \
  libcurl4-gnutls-dev \
  re2c libzip-dev

WORKDIR /usr/local/
COPY php-7.3.2.tar.gz /usr/local/
RUN gzip -d php-7.3.2.tar.gz \
  && tar -xvf php-7.3.2.tar \
  && ln -s php-7.3.2 php

WORKDIR /usr/local/php/
RUN ./configure \
  --prefix=/usr/local/php/install \
  --with-apxs2=/usr/local/apache/bin/apxs \
  --with-config-file-path=/usr/local/php-7.3.2/ \
  --enable-libgcc \
  --with-mysqli=/usr/local/mysql/install/bin/mysql_config \
  --with-pdo-mysql=/usr/local/mysql/install/ \
  --with-zlib-dir=/usr \
  --with-jpeg-dir=/usr \
  --with-png-dir=/usr \
  --with-gd=/usr/local \
  --with-freetype-dir=/usr \
  --enable-ftp \
  --enable-xml \
  --enable-zip \
  --with-bz2 \
  --enable-wddx \
  --without-pear \
  --enable-mbstring \
  --with-openssl \
  --with-curl \
  --enable-intl \
  && make \
  && make install \
  && make clean

之前,MySQL服务器是通过Dockerfile成功安装的:

FROM stephaneeybert/ubuntuos:18.04


# Installing the mysql client

RUN apt-get install -y libncurses-dev

COPY mysql-8.0.15.tar.gz /usr/local/
WORKDIR /usr/local
RUN gzip -d mysql-8.0.15.tar.gz \
  && tar -xvf mysql-8.0.15.tar \
  && mv mysql-8.0.15 mysql-source

RUN mkdir mysql
WORKDIR /usr/local/mysql/
RUN mkdir install \
  && mkdir install/data \
  && mkdir install/var \
  && mkdir install/etc \
  && mkdir install/tmp

WORKDIR /usr/local/mysql/
RUN cmake -- -j4 \
  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/install \
  -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  -DWITHOUT_TOKUDB=1 \
  -DMYSQL_DATADIR=/usr/local/mysql/install/data \
  -DDOWNLOAD_BOOST=1 \
  -DWITH_BOOST=/usr/local/mysql/install/boost \
  -DMYSQL_UNIX_ADDR=/usr/local/mysql/install/tmp/mysql.sock \
  /usr/local/mysql-source/ \
  && make \
  && make install \
  && make clean

config.log 文件有这样的内容:

configure:51849: checking for MySQLi support
configure:51885: result: yes
configure:51894: checking whether to enable embedded MySQLi support
configure:51908: result: no
configure:51917: checking for specified location of the MySQL UNIX socket
configure:51932: result: no
configure:52066: checking for mysql_set_server_option in -lmysqlclient_r
configure:52091: cc -o conftest -I/usr/include -g -O2 -fvisibility=hidden -pthread  -D_REENTRANT -Wl,-rpath,/usr/local/mysql/install/lib -L/usr/local/mysql/install/lib -L/usr/lib  -Wl,-rpath,/usr/lib/gcc/x86_64-linux-gnu/7 -L/usr/lib/gcc/x86_64-linux-gnu/7 -Wl,-rpath,/usr/local/lib -L/usr/local/lib -Wl,-rpath,/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lm -lrt -lssl -lcrypto -ldl conftest.c -lmysqlclient_r  -lstdc++ -lgd -lpng -lz -ljpeg -lpng -lz -ljpeg -lbz2 -lz -lrt -lm -ldl -lnsl  -lpthread -lgcc -lxml2 -lssl -lcrypto -lcurl -lxml2 -lssl -lcrypto -lfreetype -lfreetype -licui18n -licuuc -licudata -licuio >&5
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: error: ld returned 1 exit status

确实,lib目录下没有mysqlclient_r文件:

root@7d84572cf230:/usr/local/php# ll /usr/local/mysql/install/lib
total 78904
drwxr-xr-x  5 root root     4096 Feb 10 16:21 ./
drwxrwxr-x 17 root root     4096 Feb 10 16:21 ../
-rw-r--r--  1 root root 25593504 Feb 10 10:28 libmysqlclient.a
lrwxrwxrwx  1 root root       20 Feb 10 16:19 libmysqlclient.so -> libmysqlclient.so.21
lrwxrwxrwx  1 root root       25 Feb 10 16:19 libmysqlclient.so.21 -> libmysqlclient.so.21.0.15
-rw-r--r--  1 root root 11087808 Feb 10 10:28 libmysqlclient.so.21.0.15
-rw-r--r--  1 root root 18383678 Feb 10 16:07 libmysqlharness.a
lrwxrwxrwx  1 root root       20 Feb 10 16:21 libmysqlharness.so -> libmysqlharness.so.1
-rw-r--r--  1 root root  7750224 Feb 10 16:09 libmysqlharness.so.1
lrwxrwxrwx  1 root root       19 Feb 10 16:21 libmysqlrouter.so -> libmysqlrouter.so.1
-rw-r--r--  1 root root 17906048 Feb 10 16:11 libmysqlrouter.so.1
-rw-r--r--  1 root root    43678 Feb 10 10:30 libmysqlservices.a
drwxr-xr-x  2 root root     4096 Feb 10 16:21 mysqlrouter/
drwxr-xr-x  2 root root     4096 Feb 10 16:19 pkgconfig/
drwxr-xr-x  3 root root     4096 Feb 10 16:19 plugin/

最佳答案

将符号链接(symbolic link)添加到丢失的库文件后,configure 命令正常完成:

RUN ln -s /usr/local/mysql/install/lib/libmysqlclient.a /usr/local/mysql/install/lib/libmysqlclient_r.a

但是 make 命令稍后会失败,因为缺少 mysql 库。

但是,如果在配置命令中使用名为 mysqlnd 的 MySQL PHP native 驱动程序,则 make 命令会成功:

  --with-mysqli=mysqlnd \
  --with-pdo-mysql=mysqlnd \

关于php - 错误: wrong mysql library version or lib not found (when building PHP 7 with a custom built MySQL 8),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54625966/

相关文章:

php - SQL 在 phpMyAdmin 中有效,但在网页脚本中返回错误的行数

php - 文本移出标题标签

MySQL 程序开发而不是发送大查询

mysql - 使用 MySQL 触发器在同一表中更新行时插入新行

python - 容器外的 Docker 输入/输出

java - 从 jenkins 中的 docker 容器获取日志

php - Doctrine DBAL - 事务和插入外部事务

php - 用GD创建一张包含其他图片的图片

mysql - 当同名表已存在时,mysql innodb 重命名大表的最佳实践

docker - Kubernetes:获取网络上其他 Pod 的 IP 地址