在MAMP中连接到MySQL [英] Connect to MySQL in MAMP

查看:388
本文介绍了在MAMP中连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使HTML表单连接到MAMP上的MySQL数据库.

I'm trying to make a HTML form connect to a MySQL database on my MAMP.

但是我无法打开MySQL连接.我不断收到消息无法连接"

However I'm not able to open the MySQL connection. I keep getting the message "Could not connect"

我对此的想法-

  1. 主机不正确
  2. 用户名和/或密码不正确.我在config.inc.php中找到了此信息,所以我相信它是正确的,但是有可能..

这是PHP脚本

<?php
class Database {
    function insert() {
        $dbhost = 'localhost:8888';
        $conn = mysql_connect($dbhost, 'root', 'root');
        if (! $conn) {
            die('Could not connect: ' . mysql_error());
        }
        else {
            echo "connected";
        }
    }   
}

?>

推荐答案

此可能的解决方案线程:

a)启动MAMP,转到首选项"并将 SQL端口设置为 3306 .

a) Launch MAMP, go to Preferences and set SQL Port to 3306.

b)使用以下命令集:

b) Use this set of commands:

ps aux | grep mysql 
lsof -i 
killall -9 mysqld 

在终端中,然后重新启动MAMP.

in the Terminal and restart MAMP.

祝你有美好的一天.

这篇关于在MAMP中连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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