macOS Mojave drush mysql.sock fix

xet7.org In English > macOS Mojave drush mysql.sock fix

$ drush cc all

When drush has these errors about mysql.sock or "no such file or directory" error from PDO::__construct, or something like:

Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’

or
<h1>Additional uncaught exception thrown while handling exception.</h1><h2>Original</h2><p>PDOException: SQLSTATE[HY000] [2002] No such file or directory in drupal_is_denied() (line 2193 of /private/var/www/sites/websitename/web/includes/bootstrap.inc).</p><h2>Additional</h2><p>PDOException: SQLSTATE[HY000] [2002] No such file or directory in _registry_check_code() (line 3486 of /private/var/www/sites/websitename/web/includes/bootstrap.inc).</p><hr />Drush command terminated abnormally due to an unrecoverable error.

or

<h1>Additional uncaught exception thrown while handling exception.</h1><h2>Original</h2><p>PDOException: SQLSTATE[HY000] [2002] Too many levels of symbolic links in drupal_is_denied() (line 2193 of /private/var/www/sites/websitename/web/includes/bootstrap.inc).</p><h2>Additional</h2><p>PDOException: SQLSTATE[HY000] [2002] Too many levels of symbolic links in _registry_check_code() (line 3486 of /private/var/www/sites/weebsitename/web/includes/bootstrap.inc).</p><hr />Drush command terminated abnormally due to an unrecoverable error.

That is related to webpage https://docs.drush.org/en/7.x/configure/

Fix

1) Remove most likely unnecessary symlink to non-existing MAMP:

rm /var/mysql/mysql.sock

2) Edit your home directory .profile file:

nano ~/.profile

3) Add there path to correct PHP, your could be in different directory under Cellar (to use it instead of previous /usr/bin/php that could be 7.1.x)

export DRUSH_PHP='/usr/local/Cellar/[email protected]/5.6.32_8/bin/php'

4) Close bash and open again

5) Try again, now it should work:

cd /var/www/sites/websitename/web

drush cc all



Comments