Drupal

drupal console can’t connect to MAMP mysql server

Do you ever encountered an error while running drupal command inside drupal root directory where you using MAMP as your development stack?

$ drupal
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

OR while trying to connect mysql client with mysql server run by MAMP or MAMP Pro?

$ mysql -u root -ppassword
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This is because drupal console or mysql client try to connect to mysql server by default location of mysql socket file which is supposed to exist at /tmp/mysql.sock

But mysql server run by MAMP create this socket file at /Applications/MAMP/tmp/mysql/mysql.sock location which is different from default expected mysql socket file

Solution:

Simply create a symlink to this mysql socket file under /tmp/ directory.

$ ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

BOOM! now you can run drupal console or mysql command.

Standard

Leave a comment