bash 删除mysql表数据(Bash脚本)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7159727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:38:58  来源:igfitidea点击:

Delete mysql table data (Bash Script)

mysqlbash

提问by tike

I was wondering how to delete the values in a MySQL database table from bash.

我想知道如何从 bash 中删除 MySQL 数据库表中的值。

I have a database called "database" and a table in that database called "table".

我有一个名为“database”的数据库和一个名为“table”的数据库中的表。

Now I want to dump and clear the database from a bash script.

现在我想从 bash 脚本转储和清除数据库。

How can I delete the values?

如何删除值?

I am using:

我在用:

mysqldump database > $DB_BACKUP/01/table-`date +%Y-%m-%d` (to dump)

and now trying to

现在试图

DELETE FROM database.table WHERE filed < CURDATE()-5

回答by Jacek Kaniuk

mysql -Bse 'DELETE FROM database.table WHERE filed < CURDATE()- 5'

or

或者

mysql -Bse 'DELETE FROM table WHERE filed < CURDATE()- 5' database



mysql --help

-B, --batchDon't use history file. Disable interactive behavior. starts with this option ENABLED by default! Disable with

-B, --batch不要使用历史文件。禁用交互行为。默认情况下以启用此选项开始!禁用

-s, --silentBe more silent. Print results with a tab as separator, Buffer for TCP/IP and socket communication

-s, --silent更安静。使用制表符作为分隔符打印结果,用于 TCP/IP 和套接字通信的缓冲区

-e, --execute=nameExecute command and quit. (Disables --force and history file)

-e, --execute=name执行命令并退出。(禁用 --force 和历史文件)