<p>I manage to fix the issue after numerous of research, for those who are interested, here is the solution,</p>
<blockquote>
<p>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 &lt;mysql_port&gt; (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 &quot;tutum/mysql&quot;
is image name found in docker images</p>
</blockquote>
<p>Another solution from this is where you have to change the <strong>localhost</strong> to <strong>127.0.0.1</strong></p>
<pre><code>mysql -h localhost -P 3306 --protocol=tcp
</code></pre>
<p>Here is the link for reference,
<a href="https://stackoverflow.com/questions/23234379/installing-mysql-in-docker-fails-with-error-message-cant-connect-to-local-mysq">https://stackoverflow.com/questions/23234379/installing-mysql-in-docker-fails-with-error-message-cant-connect-to-local-mysq</a></p>
<p>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.</p>
<pre><code>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
</code></pre>
<p>Here is the link for reference,
<a href="https://forums.docker.com/t/mysql-docker-will-not-come-up-until-we-restart-the-container/105882" rel="nofollow noreferrer">https://forums.docker.com/t/mysql-docker-will-not-come-up-until-we-restart-the-container/105882</a></p>
<p>I have forgotten the exact step I use to fix this issue, because I still encounter few issues after this, so good luck.</p>

CC BY-SA 4.0
2021-06-05T09:27:28.727Z
2021-06-05T09:27:28.727Z
Lee
<p>I'm trying to sync the database from staging to local (<a href="https://craftcms.com/blog/craft-nitro" rel="nofollow noreferrer">Craft Nitro</a>) using the <a href="https://github.com/nystudio107/craft-scripts" rel="nofollow noreferrer">craft-script</a> as per the <a href="https://nystudio107.com/blog/database-asset-syncing-between-environments-in-craft-cms" rel="nofollow noreferrer">article</a>.</p>
<p>Here is the error message,</p>
<pre><code>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: &quot;Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 &quot;No such file or directory&quot;)&quot; 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
</code></pre>
<p>How can I fix this?</p>

CC BY-SA 4.0
2021-06-05T04:14:16.700Z
Does this answer your question? [SyncDB with Nitro Fail to sync database from local to staging](https://craftcms.stackexchange.com/questions/37838/syncdb-with-nitro-fail-to-sync-database-from-local-to-staging)
Brad Bell
CC BY-SA 4.0
2021-06-05T05:13:58.953Z
Is a different issue, this is using Craft Script, not SyncDB plugin.
Lee
CC BY-SA 4.0
2021-06-06T04:23:06.220Z
Sorry... my bad.
Brad Bell
<database><mysql><server><multi-environment><nitro>
MySQL error when sync database using Craft Script from Craft Nitro
# MySQL error when sync database using Craft Script from Craft Nitro

(Asked by: username_0 on 2021-06-04)

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?

**Tags:** database, mysql, server, multi-environment, nitro

> **Comments:**
> **username_1**: Does this answer your question? [SyncDB with Nitro Fail to sync database from local to staging](https://craftcms.stackexchange.com/questions/37838/syncdb-with-nitro-fail-to-sync-database-from-local-to-staging)  
> **username_0**: Is a different issue, this is using Craft Script, not SyncDB plugin.  
> **username_1**: Sorry... my bad.  

---

## 1 answers

### Answer by username_0 on 2021-06-05. Score: 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  (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.


---

