shell脚本中的Mysql数组(Linux)

标签 mysql arrays linux bash shell

我正在尝试从 mysql 中读取 id,然后删除带有 id-1 的条目。

today_time=$(date -d "now" '+%d-%b-%Y %H:%M:%S')  
query_find_id="SELECT id FROM guestlist WHERE value <= '$today_time'"

array_query=$(mysql -u $USER -p$PASSWORD $TABLE_NAME -e "$query_find_id")

array_id=($(for i in $array_query; do echo $i; done))

for j in "${array_id[@]}"; k=$j-1; mysql -u $USER -p$PASSWORD $TABLE_NAME -e "DELETE FROM guestlist WHERE id = '$k'"; done

数组每次都是空的。我做错了什么?

最佳答案

如果您的 value 列是 DATETIME,则 today_time 中的日期格式应为 %Y-%m-%d %H:%M:%S

关于shell脚本中的Mysql数组(Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25826625/

相关文章:

mysql - Yii2 - 两个查询的并集

java - 尝试将 MySQL 服务器连接到 Spring Boot App STS 时出现多个错误

mysql - 在 MySQL 嵌套 If 中检查 Null

javascript - 将一组选中的复选框的值获取到 JavaScript 数组中,并将它们传递到 ajax 请求中

linux - 将搁置的更改列表合并到分支中

php - 自动维护/"We will be back"页

python - 为什么 mysql 在与 python 一起使用时返回格式为 ('abc' ) 的字符串

arrays - 在 Nim 中创建对数组的引用

c# - 比较高性能的 int 数组

linux - 在 IntelliJ IDEA 和 Ubuntu 中打开终端