简体   繁体   中英

How to execute a “INSERT INTO” query to a remote database with linux command line?

I'm tryng to create a code in raspbian system to update a value in my database mySQL stored into my hosting server using a bash ".sh" scrypt.

this line won't to work but I don't know why...

mysql -h eliuslab.com -u user -pPassWord -D mydatabase -e "INSERT INTO 'home-IP' ('IP') VALUES ('192.168.1.2')"

And the output:

 '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 ''home-IP' ('IP') VALUES ('192.168.1.2')' at line 1 '

this query works well in a GUI mySQL client, but what I want to do is to launch this action with my ".sh" bash scrypt.

Thank you so much :)

Okay I got the solution. I ran your script in my mysql database and got the same error. It's not the fault of script but it's a parsing error. The correct command is

mysql -h eliuslab.com -u user -pPassWord -D mydatabase -e "INSERT INTO tablename (column) VALUES ('BLABLASTRING')"

Notice there is no need of using quotation marks around the table name and the column name. The quotation marks treat them as string constant rather than a container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM