Andy
Andy

Reputation: 613

How to send sql statement to remote server via ssh

I'm trying to send a sql command to a remote server:'=

command:

`mysql -u videoeditor -p12345 testing -e "UPDATE testing.video SET rtsp_url = INSERT(rtsp_url, LENGTH(rtsp_url) - LOCATE('/', REVERSE(rtsp_url)) + 2, 0, '10101');"`

my complete command to do it is:

ssh user@serverIP 'mysql -u videoeditor -p12345 testing -e "UPDATE testing.video SET rtsp_url = INSERT(rtsp_url, LENGTH(rtsp_url) - LOCATE('/', REVERSE(rtsp_url)) + 2, 0, '10101');"'

but it seems like my syntax is wrong

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/, REVERSE(rtsp_url)) + 2, 0, 10101)' at line 1

Upvotes: 0

Views: 1014

Answers (3)

georgecj11
georgecj11

Reputation: 1637

Are you passing the host name. Please try the format as

mysql -p -u <mysql_username> -h <mysql_server_ip> -e "<update query>"

Make sure there are necessary permissions from the remote server to the MySQL server

Upvotes: 0

Ruslan Zasukhin
Ruslan Zasukhin

Reputation: 389

Each single quote inside of SQL command should be replaced to '\''

Upvotes: 1

Barry Colebank Jr
Barry Colebank Jr

Reputation: 1949

You most likely have to escape the ' in the sql string since you're wrapping them inside of '' to use ssh.

ssh user@serverIP 'mysql -u videoeditor -p12345 testing -e "UPDATE testing.video SET rtsp_url = INSERT(rtsp_url, LENGTH(rtsp_url) - LOCATE(\'/\', REVERSE(rtsp_url)) + 2, 0, \'10101\');"'

Upvotes: 0

Related Questions