Error trying to recreate a database - Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This is my error ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

I have a WordPress website online, and I wanted it to be under git version control so I installed VersionPress. Then, from my server, I uploaded the now tracked site to my GitHub.

In my computer, I created a local site deleted completely the contents of LocalSites/myweblocal/app/public, and cloned my GitHub repository in this folder then I tried to restore my website following the recommended steps [1], [2] but I have get the error when I run the command wp core config --dbname='wp130' --dbuser='wp130' (wp-config.php is not tracked by VersionPress).

I guess that it is related to the MySQL that is trying to use because previously I got another error related with the php version that was trying to use.

When I run wp --info i get:

Shell:	/bin/zsh
PHP binary:	/Applications/Local.app/Contents/Resources/extraResources/site-binaries/php-7.3.5/bin/php
PHP version:	7.3.5
php.ini used:	/Users/me/Library/Application Support/Local/run/lHVEEkQsG/conf/php/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/me/Local Sites/myweblocal/app/public
WP-CLI packages dir:	
WP-CLI global config:	
WP-CLI project config:	
WP-CLI version:	2.2.0

And the database socket is the original created by Local:
found at /Users/me/Library/Application Support/Local/run/lHVEEkQsG/mysqld.sock

1 Like

Same Issue when I run any wp cli commands

1 Like

I’ve got a fresh installation of Local (Beta) v5.0.7+1117 on the freshly install MacOS 10.15.1 (19B88). I’m using iTerm with zshell (5.7.1). I’ve got a multisite installed and running. I can access MySQL via mysql -uroot -p via Open Site in Shell. The installed WP-CLI:

OS:	Darwin 19.0.0 Darwin Kernel Version 19.0.0: Thu Oct 17 16:17:15 PDT 2019; root:xnu-6153.41.3~29/RELEASE_X86_64 x86_64
Shell:	/usr/local/bin/zsh
PHP binary:	/Applications/Local.app/Contents/Resources/extraResources/site-binaries/php-7.3.5/bin/php
PHP version:	7.3.5
php.ini used:	/Users/.../Library/Application Support/Local/run/G3ayGLf9n/conf/php/php.ini
WP-CLI root dir:	phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:	phar://wp-cli.phar/vendor
WP_CLI phar path:	/Users/.../Local Sites/.../app/public
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config:
WP-CLI version:	2.2.0

However, when I try to reset the db using wp db reset I get the following answer: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2). In the Local database info, the socket is /Users/.../Library/Application Support/Local/run/G3ayGLf9n/mysqld.sock. The same value is listed in php.ini as default and master value. It is only WPCLI that can’t access the db.

I have the same problem on Ubuntu.

I’ve been getting this error ever since updating to Lightning, anyone find a fix?

edit: for anyone getting here via google etc, more current updates here: Unable to access database

Looks like this is still a thing. Such a bummer. this is a very important function and without it I’m having to do it manually via Adminer. It works but it’s not ideal.

I was finally able to resolve this with a solution on this post Unable to run Db Export via CLI

the --socket argument after my wp cli db command totally works. Completely missed this!

You can also use mysql cli to connect to the database. This is how you connect to the database on Mac. The socket path is located under the “Database” tab of your site.

    mysql -uroot -proot --socket "/Users/user/Library/Application Support/Local/run/SITE/mysql/mysqld.sock"