安装 pdo_MySQL 扩展时,找不到 MySQL 安装路径

在Linux中试过mysql / php服务都是可以正常启动是用的,但编译pdo_mysql时总是报错找不到mysql安装路径。我通过whereis及find命令尝试了很多目录都不可以。以下为代码,求大神指导。

# php -v
PHP 7.1.30 (cli) (built: Jul 17 2019 17:34:23) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

# mysql -V
mysql  Ver 14.14 Distrib 5.6.44, for Linux (x86_64) using  EditLine wrapper

# whereis mysql
mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

# ls 下载并解压后的pdo_mysql扩展文件列表
acinclude.m4  autom4te.cache  config.guess  config.log  config.nice  configure     CREDITS  install-sh  Makefile.fragments  Makefile.objects  mkinstalldirs   mysql_statement.c  php_pdo_mysql.h      php_pdo_mysql_sqlstate.h
aclocal.m4    build           config.h.in   config.m4   config.sub   configure.in  include  ltmain.sh   Makefile.global     missing           mysql_driver.c  pdo_mysql.c        php_pdo_mysql_int.h  run-tests.php

# ./configure  --with-pdo-mysql=/usr/lib64/mysql
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/extensions/no-debug-non-zts-20160303
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.14.3 (ok)
checking for gawk... gawk
checking for MySQL support for PDO... yes, shared
checking for mysql_config... not found
checking for mysql install under /usr/lib64/mysql... can not find it
configure: error: Unable to find your mysql installation

安装过程回顾
1,不要去php.net中下载扩展了,维护已经改到php的安装包中了/ext/扩展里去直接编译安装。
2,编译pdo_mysql扩展时 执行make test 出现以下报错

TIME START 2019-09-25 06:22:16
=====================================================================
PASS public static array PDO::getAvailableDrivers ( void );
array pdo_drivers ( void ); [tests/PDO_getAvaliableDrivers.phpt] 
SKIP Bug #41125 (PDO mysql + quote() + prepare() can result in seg fault) [tests/bug41125.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #44327 (PDORow::queryString property & numeric offsets / Crash) [tests/bug44327.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #46292 (PDO::setFetchMode() shouldn't requires the 2nd arg when using FETCH_CLASSTYPE) [tests/bug46292.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #44327 (PDORow::queryString property & numeric offsets / Crash) [tests/bug53551.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #53782 (foreach throws irrelevant exception) [tests/bug53782.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #54929 (Parse error with single quote in sql comment (pdo-mysql)) [tests/bug54929.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #63176 (Segmentation fault when instantiate 2 persistent PDO to the same db server) [tests/bug63176.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #66141 (mysqlnd quote function is wrong with NO_BACKSLASH_ESCAPES after failed query) [tests/bug66141.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #38671 (PDO#getAttribute() cannot be called with platform-specific attribute names) [tests/bug68371.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #70272 (Segfault in pdo_mysql) [tests/bug70272.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #70389 (PDO constructor changes unrelated variables) [tests/bug70389.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP MySQL Prepared Statements and BLOBs [tests/bug70862.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #71569 (#70389 fix causes segmentation fault) [tests/bug71569.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #75177 Type 'bit' is fetched as unexpected string [tests/bug75177.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #33689 (query() execute() and fetch() return false on valid select queries) [tests/bug_33689.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #37445 (Premature stmt object destruction) [tests/bug_37445.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #39483 (Problem with handling of \ char in prepared statements) [tests/bug_39483.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #39858 (Lost connection to MySQL server during query by a repeated call stored proced) [tests/bug_39858.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #41125 (PDO mysql + quote() + prepare() can result in segfault) [tests/bug_41125.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #41698 (float parameters truncated to integer in prepared statements) [tests/bug_41698.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #41997 (stored procedure call returning single rowset blocks future queries) [tests/bug_41997.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #42499 (Multi-statement execution via PDO::exec() makes connection unusable) [tests/bug_42499.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #43371 (Memory errors in PDO constructor) [tests/bug_43371.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #44454 (Unexpected exception thrown in foreach() statement) [tests/bug_44454.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #44707 (The MySQL PDO driver resets variable content after bindParam on tinyint field) [tests/bug_44707.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #45120 (PDOStatement->execute() returns true then false for same statement) [tests/bug_45120.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #50323 (No ability to connect to database named 't;', no chance to escape semicolon) [tests/bug_50323.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #51670 (getColumnMeta causes segfault when re-executing query after calling nextRowset) [tests/bug_51670.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL Bug #61207 (PDO::nextRowset() after a multi-statement query doesn't always work) [tests/bug_61207.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #61411 (PDO Segfaults with PERSISTENT == TRUE && EMULATE_PREPARES == FALSE) [tests/bug_61411.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #61755 (A parsing bug in the prepared statements can lead to access violations) [tests/bug_61755.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP Bug #74376 (Invalid free of persistent results on error/connection loss) [tests/bug_74376.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PDO MySQL PECL bug #1295 (http://pecl.php.net/bugs/bug.php?id=12925) [tests/bug_pecl_12925.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
SKIP PECL Bug #7976 (Calling stored procedure several times) [tests/bug_pecl_7976.phpt] reason: SQLSTATE[42000] [1049] Unknown database 'test'
PHP Warning:  opendir(/opt/php-7.1.30/ext/pdo_mysql/ext/pdo/tests): failed to open dir: No such file or directory in /opt/php-7.1.30/ext/pdo_mysql/run-tests.php on line 889

Warning: opendir(/opt/php-7.1.30/ext/pdo_mysql/ext/pdo/tests): failed to open dir: No such file or directory in /opt/php-7.1.30/ext/pdo_mysql/run-tests.php on line 889
ERROR: cannot open directory: /opt/php-7.1.30/ext/pdo_mysql/ext/pdo/tests
make: *** [test] Error 1

找了半天原因没解决,后来执行:
make & make install 成功了。
太鬼畜了,不明白为什么。

好了,至少暂时可以使用了,先继续学习。

有没有遇到这种情况的 ~ 可以一起分析分析 。

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 2

是因为缺少mysql.h文件,安装yum install mysql-devel 就好了。
之前MySQL编译安装时,应该是有错误没看到导致的。
不过即使没有mysql.h文件,居然用客户端navicat连接也能正常使用。
似乎只影响安装扩展时。

4年前 评论

我一般都是 apt install php7.2-mysql

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!