getting mysql error when running the query alognwith ssh
I may be wrong here - but isn't the echo command running on the server you're reaching via ssh - and the /usr/bin/mysql running on your local machine?

Whereas, both commands are running on the remote machine when issued on the remote machine, without the ssh?

What if you moved the ssh call to after the pipe, on the /usr/bin/mysql command?

NOTE: It's been a while since I used Unix/Linux, but a quick Google check on ssh seems to indicate this is how it works....