简体   繁体   English

sh:mysql:找不到命令PHP exec()macOS

[英]sh: mysql: command not found PHP exec() macOS

I installed mysql with Homebrew on my MacOSX Sierra. 我在MacOSX Sierra上用Homebrew安装了mysql。 Now when I try to execute the PHP function 现在,当我尝试执行PHP函数时

<?= exec("mysql --version 2>&1"); ?>

i get the error: sh: mysql: command not found 我收到错误: sh: mysql: command not found

PS: mysql is working fine from the terminal. PS:mysql从终端正常工作。

It's probable that the path used by PHP does not include the location where the mysql binary was installed. PHP所使用的路径可能不包含mysql二进制文件的安装位置。 Normally this is /usr/local/bin which is non-standard and not in the default path. 通常,这是/usr/local/bin ,它是非标准的,不在默认路径中。 Remember, altering your personal path doesn't impact the path of already running system services. 请记住,更改个人路径不会影响已经运行的系统服务的路径。

You can probably make this work by specifying the full path to the executable, that is the result of: 您可以通过指定可执行文件的完整路径来完成这项工作,这是由于以下结果:

which mysql

Which is probably /usr/local/bin/mysql . 可能是/usr/local/bin/mysql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM