[英]simple shell script to delete posts from db
Trying to run a shell script to delete posts from a wordpress database. 尝试运行Shell脚本以从Wordpress数据库中删除帖子。 At the moment it is just outputting the mysql syntax help screen.
目前,它只是输出mysql语法帮助屏幕。 I was wondering if someone could help me debug this script:
我想知道是否有人可以帮助我调试此脚本:
#!/bin/bash
mysql -u ***** -p***** admin-wp "SELECT * FROM admin_wp.wp_8_posts LIMIT 0, 10
WHERE post_type = 'post' AND DATEDIFF(NOW(), post_date) > 30" << EOFMYSQL
If you're putting the query in the command line, you introduce it with the -e
option, and you don't need <<EOFMYSQL
. 如果将查询放在命令行中,则使用
-e
选项将其引入,并且不需要<<EOFMYSQL
。
mysql -u ***** -p***** admin-wp -e "SELECT * FROM admin_wp.wp_8_posts WHERE post_type = 'post' AND DATEDIFF(NOW(), post_date) > 30 LIMIT 0, 10 "
If you want to use a here-doc, you put it after the command: 如果要使用here-doc,请将其放在命令后面:
mysql -u ***** -p***** admin-wp <<EOFMYSQL
SELECT *
FROM admin_wp.wp_8_posts
WHERE post_type = 'post' AND DATEDIFF(NOW(), post_date) > 30
LIMIT 0, 10
EOFMYSQL
Also, your SQL syntax was wrong. 另外,您的SQL语法错误。
LIMIT
has to come after WHERE
. LIMIT
必须在WHERE
之后。 BTW, it doesn't make much sense to use LIMIT
without ORDER BY
-- it will just pick any random 10 rows from the results. 顺便说一句,在没有
ORDER BY
情况下使用LIMIT
并没有多大意义-它只会从结果中随机选择10行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.