无法使用MAMP或社区服务器连接到mysql服务器 [英] Cannot connect to mysql server with MAMP nor with Community Server

查看:507
本文介绍了无法使用MAMP或社区服务器连接到mysql服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MySQL Workbench创建了一个数据库,现在我需要访问它。所以我写了一个php脚本来访问它:

I created a database with MySQL Workbench, and now I need to access it. So I've written a php script to access it:

<? 
    $db = mysql_connect("127.0.0.1:3306","root", "");

    if (!$db){
        echo "Could not connect to database";
        exit();
    }

    $db_name = "pfc_db";
    if (!mysql_select_db($db_name, $db)){
        die ("Could not select database");
    }

    $sql=mysql_query("select * from CAPAS");
    while($row=mysql_fetch_assoc($sql)){
        $output[]=$row;
        if (isset($output)){
            echo "yes";
            echo $output[0];
        }
        else{echo "no";}
    }
    mysql_close();

?>

我对MAMP和MySQL社区服务器有疑问,我需要推送正确的路径。
我在我的Mac上安装了MAMP,并将端口切换到默认的mysql 3306.我把PHP测试脚本放在我在htdocs下创建的文件夹Api中。所以,试试看我在我的浏览器上键入 http://127.0.0.1/api/test.php,结果是无法连接到数据库。我是做正确的吗?

I have doubts about MAMP and MySQL Community Server and I need a push on the right path. I've installed MAMP on my mac and switched the ports to the default mysql ones 3306. I've placed the PHP test script in a folder "Api" I've created under htdocs. So to try it out i type on my browser http://127.0.0.1/api/test.php and the result is "Could not connect to databse". Am I doing it right?

社区服务器?它比MAMP好吗?是否应该运行MAMP工作?我可以只使用社区服务器吗?如果是这样,我应该在哪里放置PHP脚本?哪个文件夹?因为当我尝试用社区服务器做相同的测试,而不是显示错误消息,浏览器开始下载php脚本到我的下载文件夹。为什么会发生这种情况?

And what about Community Server? Is it better than MAMP? Should it be running for MAMP to work? Can I just use Community Server? If so, where should I place the PHP scripts? Which folder? Because when I try to do the same test with Community Server, instead of showing the error message, the browser starts downloading the php script to my downloads folder. Why happens that?

正如你所看到的,我在这些服务器的东西有点混乱,我需要一些帮助来弄清楚。

As you can see I have a bit of a mess in my mind with these server stuff and I need some help to figure it out.

推荐答案

好,我要回答自己,如果有人遇到同样的问题。

Well, I'm gonna answer myself so that if someone runs into the same problem.

密码的错误发生是因为我在同一台计算机上安装了两个mysql,所以我正在检查其中一个密码,浏览器正在查看其他密码。

The error of password happened because I had two installations of mysql in the same computer, so that I was checking the passwords in one of them and the browser was looking at the other.

因此,如果您有密码访问的问题,请检查您没有安装两个mysql并检查文件config.inc.php

Therefore, if you have problems with password access, check that you don't have two mysql installed and also check the file config.inc.php

我也通过套接字连接改变了TCP / IP,如果你使用localhost作为服务器,这将提高速度。

I also changed TCP/IP by a socket connexion, which improves the speed if you're using your localhost as server.

这篇关于无法使用MAMP或社区服务器连接到mysql服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆