gpt4 book ai didi

mysql - 将时间戳插入 shell 中的 mysql 列

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:24:51 24 4
gpt4 key购买 nike

以下对我有用:

mysql -u 'root' -h 8.8.8.88 mo -e 'UPDATE `path_last_updated` 
SET timestamp="2012-01-03 00:00:00"'

但是,以下内容不会:

TIMESTAMP=`date "+%Y-%m-%d-%T"`
mysql -u 'root' -h 8.8.8.88 mo -e 'UPDATE `path_last_updated`
SET timestamp=$TIMESTAMP'

我如何将来自 unix 的时间戳插入到我的 mysql 表中?

更新:

TIMESTAMP=`date "+%Y-%m-%d %T"`
mysql -u 'root' -h 8.8.8.88 mo -e "UPDATE `path_last_updated`
SET timestamp='$TIMESTAMP'"

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 'SET
timestamp='2013-01-31 15:46:00'' at line 1

最佳答案

Shell 变量插值 only works between double quotes ("), not single (') .那里还有反引号,它在双引号字符串中将被视为嵌入式 shell 命令。

尝试:

mysql -u 'root' -h 8.8.8.88 mo -e "UPDATE \`path_last_updated\`
SET timestamp='$TIMESTAMP'"

另外,首先,在日期命令的格式中,%d 和 %T 之间有一个额外的破折号 (-)。

关于mysql - 将时间戳插入 shell 中的 mysql 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14637177/

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