我尝试使用以前接受的解决方案来解决我的问题,但它们不起作用:
示例“id_list”
[jlefler@server ~]$ cat id_list | tail -10
17900018
17900019
17900020
17900021
17900022
17900023
17900024
17900025
17900026
17900027[jlefler@server ~]$ cat id_list |wc -l
51624
我尝试执行的一次转储2000个ID的命令:
xargs -a id_list -d '\n' -n 2000 sh -c 'mysqldump -uuser -ppassword --compact --no-create-info db table_name --where="id in ($0 $@)" >> dump.sql' x
但是,我得到了以下意外输出:
[jlefler@server ~]$ xargs -a id_list -d '\n' -n 2000 sh -c 'mysqldump -uuser -ppassword --compact --no-create-info db table_name --where="id in ($0 $@)" >> dump.sql' x
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17851966
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17853966
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17855967
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17857967
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17859975
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17861978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17863978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17865978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17867978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17869978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17871978
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17873979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17875979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17877979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17879979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17881979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17883979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17885979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17887979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17889979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17891979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17893979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17895979
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17897980
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17899986
Warning: Using a password on the command line interface can be insecure.
"ysqldump: Couldn't find table: "17850378
基本上,最终结果应该是这样的:
mysqldump -uuser -ppassword --compact --no-create-info db table_name --where="id in (17900018,17900019,17900020...)" >> dump.sql
它一次取2000个ID,将它们添加到dump.sql中,然后继续下一个2000个ID,直到从文件中读取所有ID。
使用echo命令显示输出,我得到以下结果:
)17853963ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17851964
)17855964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17853964
)17857964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17855965
)17859972ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17857965
)17861975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17859973
)17863975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17861976
)17865975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17863976
)17867975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17865976
)17869975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17867976
)17871975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17869976
)17873976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17871976
)17875976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17873977
)17877976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17875977
)17879976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17877977
)17881976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17879977
)17883976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17881977
)17885976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17883977
)17887976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17885977
)17889976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17887977
)17891976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17889977
)17893976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17891977
)17895976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17893977
)17897977ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17895977
)17899983ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17897978
)17850375ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (17899984
17900027)mp -uuser -ppassword --compact --no-create-info db table_name --where=id in (17850376
)17853963ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17851964
)17855964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17853964
)17857964ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17855965
)17859972ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17857965
)17861975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17859973
)17863975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17861976
)17865975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17863976
)17867975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17865976
)17869975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17867976
)17871975ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17869976
)17873976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17871976
)17875976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17873977
)17877976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17875977
)17879976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17877977
)17881976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17879977
)17883976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17881977
)17885976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17883977
)17887976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17885977
)17889976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17887977
)17891976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17889977
)17893976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17891977
)17895976ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17893977
)17897977ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17895977
)17899983ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17897978
)17850375ump -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17899984
17900027)mp -uuser -ppassword --compact --no-create-info db table_name --where=id in (x 17850376
1条答案
按热度按时间lpwwtiir1#
备注:
id_list
)中的dos/windows行尾(\r\n
)引起的\r
字符,下一个问题可能是无效的in()
列表...这也是本答案的重点...输入文件示例:
修改的
xargs
调用:添加
echo
以查看当前代码生成的内容:备注:
bash
,因此我已将sh -c
替换为bash -c
--where/in()
子句中的空格替换为逗号--where/in()
子句周围显示它们解决这些问题的一个想法是: