简体   繁体   中英

MAMP - SQLSTATE[HY000] [2002] Connection refused

I'm totally confused here. I have MAMP on an iMac it says MySQL is running. When I try access it via Sequel Pro I can connect using the socket option

在此处输入图片说明

However if I try to connect using the Standard method I get a 'connection refused'

**在此处输入图片描述**

在此处输入图片说明

When I try connect with PHP I get the connection refused message

$db = new PDO("mysql:host=127.0.0.1:8889;dbname=wabie_centraldb", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""') );

I'm confused because obviously mysql is running (because I can connect one way).

I have the same setup on my MacBook and it all works perfectly

Any suggestions?

Many Thanks!

The standard port for MySQL is 3306 and does not need to be specified in the connection:

$db = new PDO("mysql:host=127.0.0.1;dbname=wabie_centraldb", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""') );

To specify a database connection port use the following DSN string:

$db = new PDO("mysql:host=127.0.0.1;port=3306;dbname=wabie_centraldb", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET sql_mode=""') );

You can test 3306 in your Sequel Pro in your standard connection. In addition, you may have to change the host from 127.0.0.1 to localhost depending on how you're set up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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