mysqldump指定数据表导出

作者:matrix 发布时间:2021年3月31日 分类:mysql

平时习惯使用mysql客户端工具直接导出表数据,这突然需要导出指定前缀的表反而变得麻烦,因为表非常多但又不想全部选择。

e.g. 导出dict_开头的数据表

查询符合条件的表名

select table_name from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'heal' and table_name like 'dict_%';

执行导出命令

mysqldump --column-statistics=0 -h 127.0.0.1 -P3306 -pPASSWORD  -t heal -uroot --tables dict_union dict_tag > ~/db_script.sql

-P端口号
-p密码
--tables 指定多个数据表

报错 mysqldump: Couldn't execute

mysqldump: Couldn't execute 'SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM, '$."number-of-buckets-specified"')                FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = 'heal' AND TABLE_NAME = 'dict_union';': Unknown table 'COLUMN_STATISTICS' in information_schema

需要添加参数--column-statistics=0

参考:

https://www.cnblogs.com/commissar-Xia/p/10302336.html

https://researchlab.github.io/2017/02/22/mysql-import-export-summary/