dsz7121 2018-07-14 14:26
浏览 228
已采纳

mysqli_connect error 2002“No such file or directory”Mac OS 10.13.2

I know questions related to this have been asked a zillion times on Stackoverflow and elsewhere, however, I can't seem to zero in on a resolution.

I am using a nearly fresh-out-of-the-box Macbook 13 running OS 10.13.6 High Sierra.

My goal is to create a development environment with MAMP such that I can create dynamic webpages and I'd like to use Tableau for analytics drawing data out of MySQL.

I have successfully installed and run MAMP - I have created a simple database using phpMyAdmin - and I have connected Tableau to this database successfully - this works very well.

With that in operation, I shifted my attention to trying to run php from my browser. Entering "localhost" yielded the "It works!" result.

All good so far but here is where things go off the rails: I cannot connect to MySQL via a php file using the following (****** = my root password) - filename: test_connect0.php:

<?php
$link = mysqli_connect("localhost", "root", "*****");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL ."<br>";
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL ."<br>";
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL ."<br>";
    exit;
}
echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>

What returns from running Safari or Chrome - doesn't matter - is the familiar issue: 2002 No such file or directory.

BELIEVE ME, I have searched all over the internet for solutions and I believe I have tried each and everyone to no avail.

Here are a few things I have done:

  1. Running phpInfo from MAMP returns the expected path to php.ini: /Applications/MAMP/bin/php/php7.2.1/conf
  2. In that php.ini file, the mysqli.default_socket is /Applications/MAMP/tmp/mysql/mysql.sock and that file does indeed exist
  3. Running phpInfo from MAMP indicates the php version is 7.2.1
  4. In /etc/apache2, I edited httpd.conf and uncommented LoadModule php7_module libexec/apache2/libphp7.so
  5. I have tried a number of different ways to run the test_connect0.php file: localhost/test_connect0.php localhost:3306/test_connect0.php 127.0.0.1/test_connect0.php 127.0.0.0/test_connect0.php

An observation: In item 3 above, I noted that phpInfo from MAMP returns 7.2.1 as the version. When I run a phpinfo() script from the browser, however, it returns 7.1.16. I can't explain why that's a different php version and I cannot even FIND version 7.1.16 on my machine AND I'm not sure any of that really matters.

To summarize, I have a functional MAMP and a functional Tableau connection to MAMP's MySQL. What I can't do is connect to MySQL from a php file run in the browser - I get the 2002 error.

What other information can I provide to help zero in on a solution?

  • 写回答

1条回答 默认 最新

  • dongxian6285 2018-07-15 13:31
    关注

    I found the solution:

    PHP script fix: Originally, I had my test_connect0.php script in /Library/WebServer/Documents. It turns out, it needs to be in /Applications/MAMP/htdocs. Once I moved the file to that location, I entered this url into the browser: localhost:8888/test_connect0.php

    That resulted in a successful connection to MAMP's MySQL.

    Tableau notes: As I noted earlier, I was able to connect Tableau to MySQL, however, it wasn't connecting to MAMP's MySQL. To shift Tableau to see MAMP's MySQL, I entered the following into Tableau's dialog:

    Server: localhost Port: 8888 Username: root Password: ******

    Two things are necessary ahead of time:

    1. Install the OBDC drivers per Tableau's instructions
    2. Run this in a terminal window: sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么