Samantha
Samantha

Reputation: 91

gunzip and mysql import - No such file or directory

I have created a bash script for the automation of my database restore. When I run the following commands, I get /my/sql/file/path.sql: No such file or directory.

ssh $USER@"$cloneMysqlHost" gunzip /path/file.sql.gz && MySQL -u root -p db_name < /path/file.sql 

I did an ls -lrot on the host I ssh to, just to make sure the file exists the permissions are correct, and they are.

Any ideas what I'm doing wrong?

Thanks in advance!

Upvotes: 2

Views: 1659

Answers (2)

Etan Reisner
Etan Reisner

Reputation: 80931

The && is causing the local shell to split the command and run the MySQL command locally.

The < redirection is also being done locally (and the cause of your error).

The gunzip is being performed on the remote host though.

You need to quote the entire argument to ssh if you want it all run on the remote system.

ssh "$USER@$cloneMysqlHost" 'gunzip /path/file.sql.gz && MySQL -u root -p db_name < /path/file.sql'

Upvotes: 2

Adam Axtmann
Adam Axtmann

Reputation: 236

Are you providing the password properly? Also, not sure what's going on with the &&, should use a pipe there. MySql is probably not valid, use mysql. See here for more details.

ssh $USER@"$cloneMysqlHost" gunzip /path/file.sql.gz | mysql -u root -p [password] db_name

Upvotes: 0

Related Questions