开发需求:每个表dump出部分数据

mysqldump 每张数据表统一导出的N个记录数

需求:

在开发过程中,需要将生产的数据导出到本地开发环境,希望可以每个表都导出部分数据.由于生产数据表都是上千万或亿级别,直接从服务器导出数据会影响业务, 希望可以导出部分数据用于测试环境使用。

实现:

利用mysqldump参数来实现

  • --where='where_condition', -w 'where_condition'

Dump only rows selected by the given WHERE condition. Quotes around the condition are mandatory if it contains spaces or other characters that are special to your command interpreter.

  • --where/-w 参数,它用来设定数据导出的条件,

mysqldump -u用户名 -p密码 库名 表名 --where="筛选条件" > 导出文件路径

  • 详细如下:
mysqldump -uroot -p -B employees --set-gtid-purged=OFF --where="true limit 100" > /software/every100.sql
或者
mysqldump -uroot -p -B employees --set-gtid-purged=OFF --where="1=1 limit 100 " > /software/every100.sql --employees库,每个表导出100条数据

mysql -uroot -p'xxxxxxxx' -h192.168.xxx.xxx -e "show databases"|grep -Ev "Database|sys|information_schema|mysql|performance_schema|test"|xargs mysqldump -uroot -p'xxxxxxxx' -h192.168.xxx.xxx  --add-drop-table --flush-logs --single-transaction --master-data=2  -R --databases --where="1=1 limit 100" > each_100_`date +"%Y%m%d"`.sql
  • --where="true limit N"

这个参数指为每个表增加一个LIMIT N 语句,导出时使用的是WHERE 拼接上 true limit, 拼接成where true limit N的语句并每个表统一导出的N个记录数.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值