1

From a Windows command line I am connecting via OpenSSH to a remote server to run a MySql query and save the output to a file

Here are the iterations of the command I have attempted.

ssh [email protected]  "mysql -e 'SELECT * FROM table WHERE 1;' > ./test.csv"
ssh [email protected]  "mysql databasename -e 'SELECT * FROM BLM_FIS_Orders WHERE 1;' > ./test.csv"
ssh -L 3307:127.0.0.1:3306 [email protected] "mysql --defaults-file='/home/user/.my.cnf' --database=databasename 'SELECT * FROM table WHERE 1;' > ./test.csv"

All I am getting in return is the MySql command line help information.

When I am at the ssh command line and I run the query mysql -e 'SELECT * FROM table WHERE 1;' > ./test.csv it works fine.

My .my.cnf file contains

[client]
user = username
password = password
host = 127.0.0.1
[mysql]
database = databasename

Any help is appreciated.

G.

grawity,

Thank you for replying and your question. I am using Windows CMD on the client side and the server side is WP Engine so I believe the cli would be bash. The result of

ssh [email protected] "printf /%s/ 'one two three' 'four five'"

is /one//two//three//four//five/

G.

Anyone have any ideas?

3
  • What shell are you using, both locally (powershell or cmd or WSL bash) and remotely (bash or tcsh or whatever)? If you do a ssh [email protected] "printf /%s/ 'one two three' 'four five'" does it retain the two distinct arguments or does it merge/resplit them?
    – grawity
    Commented Feb 18 at 11:16
  • I don't get this problem on my W10 using the MS-supplied port of OpenSSH. Have you installed (and put early in your PATH) some other build, such as cygwin mingw mingw64 gpg4win wsl etc? If not certain use where ssh to determine what you are running. Commented Mar 1 at 2:46
  • I am using MS-Supplied SSH from the windows CMD. I have also used Plink and have the same result. The connection is being made and the SQL command appears to be attempted, but the returned data is the help data on using MySQL from the command line. It's as if the command I have is incorrect, but it runs fine when I use it from the command line. Only when it is from an SSH connection does it fail.
    – Greg
    Commented Mar 4 at 21:00

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.