0

Having issues running a shell script that invokes mysqdump to import the database. This is for the importing of a WordPress database from production to local dev machine. It worked in the past. But something must have changed on my local MacOs Mac Mini running OSX Sierra. This is the script:

# sync-prod.sh
read -r -p "Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then
    wp @development db reset --yes
    wp @production db export - > sql-dump-production.sql
    wp @development db import sql-dump-production.sql
    wp @development search-replace https://example.com http://example.test
else
    exit 0
fi

when I run it I get:

./sync-production.sh
Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] y
Success: Database reset.
/usr/bin/env: ‘mysqldump’: No such file or directory
Success: Imported from 'sql-dump-production.sql'.
Error: The site you have requested is not installed.

When I run mysqldump

jasper@~/webdesign/example.com/site $ which mysqldump
/usr/local/bin/mysqldump

from the terminal it starts fine:

$ mysqldump
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

Read env: mysql: No such file or directory after `wp import` and tried adjusting the $PATH and now have

echo $PATH
/usr/local/sbin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/sbin:/usr/local/sbin:/usr/local/sbin:/Users/jasper/.rvm/gems/ruby-2.3.3/bin:/Users/jasper/.rvm/gems/ruby-2.3.3@global/bin:/Users/jasper/.rvm/rubies/ruby-2.3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/Users/jasper/.rvm/bin:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/mysql/bin:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql:/Users/jasper/.composer/vendor/bin:/usr/local/bin:/usr/local/bin/mysql

In .bash_profile I have

alias ll='ls -lGaf'
export PATH="/usr/local/sbin:$PATH"
export PATH="$PATH:$HOME/.composer/vendor/bin"
export PATH=$PATH:/usr/local/bin
export PATH=$PATH:/usr/local/bin/mysql
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*

###-tns-completion-start-###
if [ -f /Users/jasper/.tnsrc ]; then
    source /Users/jasper/.tnsrc
fi
###-tns-completion-end-###
export PS1="\u@\w $ "

When I run wp @production db check things do connect and are fine. I also can connect to the database over ssh using the same username and password using SequelPro.. Any ideas why I still get no such file or directory for running mysql as part of this script?

rhand
  • 1,176
  • 4
  • 17
  • 45

2 Answers2

1

What happens when you run env mysqldump command in shell? You can install and use strace for example and run the script or just the failing command like strace -F <command>. Maybe you will reveal more details about this error.

patok
  • 181
  • 1
  • 9
  • `env mysqldump 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` – rhand Jan 31 '18 at 09:42
  • 1
    try starting `dtruss ./sync-production.sh` (dtruss should be Mac OS X alternative for strace - sorry for that, I am not Mac OS X user). But it seems to me there could be problem with not specifying shell in the script... try to add `#!/bin/bash` at the first line of sync-production.sh script and run it again – patok Jan 31 '18 at 11:11
  • `dtruss ./sync-production.sh dtrace: system integrity protection is on, some features will not be available dtrace: failed to execute ./sync-production.sh: dtrace cannot control executables signed with restricted entitlements` Did also add the shebang part an ran it.. Did not help though. Wonder if it is the size... 18MB.. – rhand Jan 31 '18 at 12:04
  • are you running dtruss with sudo? I mean: `sudo dtruss ./sync-production.sh`; alternatively try [this](https://stackoverflow.com/questions/33476432/is-there-a-workaround-for-dtrace-cannot-control-executables-signed-with-restri) to disable the protection; size of what, the script itself? – patok Jan 31 '18 at 12:35
  • `sudo dtruss ./sync-production.sh Password: dtrace: system integrity protection is on, some features will not be available dtrace: failed to execute ./sync-production.sh: dtrace cannot control executables signed with restricted entitlements` I meant 18MB for the .sql file, yes – rhand Jan 31 '18 at 12:41
  • `wp -vvv @production db export - > sql-dump-production.sql PHP Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in wp-includes/wp-db.php on line 1531 Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in wp-includes/wp-db.php on line 1531 Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This ...` – rhand Jan 31 '18 at 12:49
0

The remote server did (no longer) have mysql-client installed. Once I did apt install mariadb-client-10 things started working again:

wp @production db export sql-dump-production.sql
Success: Exported to 'sql-dump-production.sql'.

and I could also run:

./sync-production.sh
Do you solemnly swear that you have had fewer than 2 alcoholic beverages in the last hour and that you would really like to reset your development database and pull the latest from production? [y/N] y
Success: Database reset.
Success: Imported from 'sql-dump-production.sql'.
.........
rhand
  • 1,176
  • 4
  • 17
  • 45