Mysql 如何通过ssh向远程服务器发送sql语句

Mysql 如何通过ssh向远程服务器发送sql语句,mysql,sql,bash,Mysql,Sql,Bash,我正在尝试向远程服务器发送sql命令:'= 命令: `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');"` 我的完整命令是: sshuser@serverIP'mysql-u videoeditor-p12345 testi

我正在尝试向远程服务器发送sql命令:'=

命令:

`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');"`
我的完整命令是:

sshuser@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');”

但我的语法似乎是错的

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

您很可能必须转义sql字符串中的“”,因为您要将它们包装在“”中才能使用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\');"'

在传递主机名时,SQL命令中的每个引号都应替换为“\”

。请尝试以下格式:

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

确保从远程服务器到MySQL服务器都有必要的权限

有什么线索可以让这一切顺利进行吗?到处都在寻找答案。非常感谢。