标题Linux下查mysql数据按数量 split生成的文件
#!/bin/bash
#数据库地址 端口 用户
mysql_address=127.0.0.1
mysql_port=3306
mysql_user=root
#每个文件多少行
export_count=300000
#输出文件的位置
file_path=/usr/local/file
mkdir -p ${file_path}
date=$(date +'%Y%m%d%H%M%S')
echo $(date) export starting !!!
mysql -u${mysql_user} -h${mysql_address} -P${mysql_port} -p database-N -e "select concat_ws(',',a,b,c) from user;" | split -l ${export_count} -d -a 4 - file_${date} --additional-suffix=.unl
mv *.unl ${file_path}
echo $(date) export sucess !!!
split 命令参数
Usage: split [OPTION]... [INPUT [PREFIX]]
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default
size is 1000 lines, and default PREFIX is 'x'. With no INPUT, or when INPUT
is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-a, --suffix-length=N 生成长度为N的后缀(默认值2)
--additional-suffix=SUFFIX 文件名后面附加一个后缀
-b, --bytes=SIZE 按大小切割文件 -b 10k/10m/..
-C, --line-bytes=SIZE 按字节切割文件类-b
-d, --numeric-suffixes[=FROM] 使用数字后缀替代字母
FROM changes the start value (default 0)
-e, --elide-empty-files 不生成带有'-n'的空输出文件
--filter=COMMAND write to shell COMMAND; file name is $FILE
-l, --lines=NUMBER 按行切割文件
-n, --number=CHUNKS 按生成文件个数切割
-u, --unbuffered immediately copy input to output with '-n r/...'
--verbose 打印日志
--help 打印帮助文档
--version 输出版本信息并退出