Drush cannot connect to MySQL on MAMP?

旧城冷巷雨未停 提交于 2019-12-04 09:27:16
chrisblomm

Lets start with saying that i am not familiar with Drush at all. But looking at this from a MAMP perspective i think i know what is going on here.

The line PDO::__construct(): [2002] No such file or directory (trying to connect via [warning] unix:///var/mysql/mysql.sock) environment.inc:523 says it all.

By default MAMP is creating the MySQL socket in /Applications/MAMP/tmp/mysql/mysql.sock as stated on the MAMP launch page. However Drush is expecting the socket at var/mysql/mysql.sock.

Well there are two ways to fix this.

  1. Stop all MAMP servers. Edit the file /Applications/MAMP/bin/startMysql.sh, change --socket=/Applications/MAMP/tmp/mysql/mysql.sock into --socket=/var/mysql/mysql.sock. And don't forget to edit stopMysql.sh as well. This tells MAMP to store the socket elsewhere the next time it boots up the Mysql server.

  2. Create a symlink from /var/mysql/mysql.sock to /Applications/MAMP/tmp/mysql/mysql.sock see this post for more info on symlinks. MAMP will need to be running for you to do this, as the socket file is created dynamically.

Good luck!

I had the same issue - what solved it for me was changing the database host in settings.php from "localhost" to "127.0.0.1".

For me the mysql bin was not existant.

sudo ln -s /Applications/MAMP/Library/bin/mysql /usr/bin/mysql

Fixed it for me.

As an alternative to answer #1, I would recommend you change your command-line MySQL to use MAMP's - this makes sure when you mysql from the command line, that works too. Edit your ~/.bash_profile and add the following line:

alias mysql='/Applications/MAMP/Library/bin/mysql'

This worked for me

sudo mkdir /var/mysql sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /var/mysql/mysql.sock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!