MySQL 带有 --where 子句的 mysqldump 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26261670/
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-08-31 13:06:14  来源:igfitidea点击:

mysqldump with --where clause is not working

mysqlsqlmysqldump

提问by nodejsj

 mysqldump -t -u root -p  mytestdb mytable --where=datetime LIKE '2014-09%'

This is what I am doing and it returns:

这就是我正在做的事情,它返回:

mysqldump: Couldn't find table: "LIKE"

I am trying to return all the rows where the column datetimeis like 2014-09meaning "all September rows".

我试图返回所有在列的行datetimelike 2014-09的意思是“整个9月行”。

回答by Leonardo Herrera

You may need to use quotes:

您可能需要使用引号:

mysqldump -t -u root -p  mytestdb mytable --where="datetime LIKE '2014-09%'"

回答by Timofey Bugaevsky

Selecting dates using LIKE is not a good idea. I saw this method in one project. This causes huge DBMS load and slow system operation as no index by this table column used.

使用 LIKE 选择日期不是一个好主意。我在一个项目中看到了这种方法。这会导致巨大的 DBMS 负载和缓慢的系统操作,因为没有使用此表列的索引。

If you need to select date range use between:

如果您需要选择日期范围,请使用:

where datetime between '2014-09-01' and '2014-09-30 23:59:59'