gpt4 book ai didi

mysql - 如何使用 linux 命令行对远程数据库执行 "INSERT INTO"查询?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:26:38 25 4
gpt4 key购买 nike

我正在尝试在 raspbian 系统中创建一个代码,以使用 bash“.sh”scrypt 更新存储在我的托管服务器中的数据库 mySQL 中的值。

这条线行不通,但我不知道为什么...

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

输出:

 '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 '

此查询在 GUI mySQL 客户端中运行良好,但我想做的是使用我的“.sh”bash scrypt 启动此操作。

非常感谢:)

最佳答案

好的,我找到了解决方案。我在我的 mysql 数据库中运行了你的脚本并得到了同样的错误。这不是脚本的错,而是解析错误。正确的命令是

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

请注意,无需在表名和列名两边使用引号。引号将它们视为字符串常量而不是容器。

关于mysql - 如何使用 linux 命令行对远程数据库执行 "INSERT INTO"查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33812937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com