1

I'm trying to sync the database from staging to local (Craft Nitro) using the craft-script as per the article.

Here is the error message,

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")" when trying to connect
mysite-db-dump-20210604.sql.gz                                                                   100%   45     6.1KB/s   00:00    
mysqldump: Got error: 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) when trying to connect
*** Backed up local database to /tmp/mysitesite-db-backup-20210604.sql.gz
'zip: invalid option -- '
Try `gzip --help' for more information.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
*** Restored local database from /tmp/mysite-db-dump-20210604.sql.gz

How can I fix this?

3
1

I manage to fix the issue after numerous of research, for those who are interested, here is the solution,

Check output of docker ps command and look for running mysql containers. If you find one then use mysql command like this: mysql -h 127.0.0.1 -P <mysql_port> (you will find port in docker ps output). If you can't find any running mysql container in docker ps output then try docker images to find mysql image name and try something like this to run it: docker run -d -p 3306:3306 tutum/mysql where "tutum/mysql" is image name found in docker images

Another solution from this is where you have to change the localhost to 127.0.0.1

mysql -h localhost -P 3306 --protocol=tcp

Here is the link for reference, https://stackoverflow.com/questions/23234379/installing-mysql-in-docker-fails-with-error-message-cant-connect-to-local-mysq

If you having access denied, you may try the below solution, where my-mysql-container is your container name (eg. mysql.database.nitro). Please take note that this will remove your database, try to look for other solutions before coming to this.

docker pull mysql 
docker stop my-mysql-container 
docker rm my-mysql-container 
docker run --name=my-mysql-container --restart=always -e MYSQL_ROOT_PASSWORD=mypwd -v /my/data/dir:/var/lib/mysql -d mysql

Here is the link for reference, https://forums.docker.com/t/mysql-docker-will-not-come-up-until-we-restart-the-container/105882

I have forgotten the exact step I use to fix this issue, because I still encounter few issues after this, so good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.