Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以根据where条件下的数据值从mysql中的单个select查询中获取多个outfile?_Mysql_Linux - Fatal编程技术网

有没有一种方法可以根据where条件下的数据值从mysql中的单个select查询中获取多个outfile?

有没有一种方法可以根据where条件下的数据值从mysql中的单个select查询中获取多个outfile?,mysql,linux,Mysql,Linux,我有一个文件,其中包含一个表的特定列值,例如file.txt 1. 2. 3. ... 在shell脚本中,我使用如下值循环select语句 文件=$1 对于cat$文件中的行 做 选择*到outfile'/path/filename.txt'中,其中colvalue='$line'; 现在,我想要一种方法,对于每个值,即1,2,3,将输出写入同一个文件。在理想情况下,它会抛出一个错误,因为“文件已存在”。请尝试以下操作: 排序和uniq删除重复的入口 sed将annd,并引用args tr-

我有一个文件,其中包含一个表的特定列值,例如file.txt 1. 2. 3. ... 在shell脚本中,我使用如下值循环select语句 文件=$1 对于
cat$文件中的行
做 选择*到outfile'/path/filename.txt'中,其中colvalue='$line'; 现在,我想要一种方法,对于每个值,即1,2,3,将输出写入同一个文件。在理想情况下,它会抛出一个错误,因为“文件已存在”。

请尝试以下操作: 排序和uniq删除重复的入口 sed将annd,并引用args tr-d将删除换行符(仅适用于光纤)

我的输入文件

$ cat n.txt
1
3
5
66
99
2
生成查询

$ echo "select * into outfile '/path/filename.txt' where colvalue in (" > query.sql
$ sort n.txt | uniq |sed -e "s/^\(.*\)$/'\1'/" -e '2,$s/^/,/g' | tr -d '\n' >> query.sql
$ echo ");" >> query.sql
$ cat query.sql
select * into outfile '/path/filename.txt' where colvalue in (
'1','2','3','5','66','99');
$ mysql -u root < query.sql
显示查询(仅用于验证)

运行查询

$ echo "select * into outfile '/path/filename.txt' where colvalue in (" > query.sql
$ sort n.txt | uniq |sed -e "s/^\(.*\)$/'\1'/" -e '2,$s/^/,/g' | tr -d '\n' >> query.sql
$ echo ");" >> query.sql
$ cat query.sql
select * into outfile '/path/filename.txt' where colvalue in (
'1','2','3','5','66','99');
$ mysql -u root < query.sql
$mysql-u root
您可以在linux上完成。请给我看一个txt文件的示例,它是一个id值文件。txt 56879 656586 87879每个文件都有一个换行符(不是一行)