mysqldump根据通配符批量导出
#库test,要将t1开头和t2开头的表导出为stru.sql,最后将stru.sql导入目标库。
CREATE TABLE `t1` (`id` int(11) DEFAULT NULL,`name` varchar(200) DEFAULT NULL)
ENGINE=InnoDB DEFAULT CHARSET=latin1;
#LOCK TABLES `t1` WRITE;
INSERT INTO `t1` VALUES (1,‘n1‘);
CREATE TABLE t2 LIKE t1;
insert into t2 select * from t1;
#查看以t1和t2开头的表
mysql -uroot -pmysql -e "show tables from test where tables_in_test like ‘t1%‘ or tables_in_test like ‘t2%‘";
#语法结构
SHOW TABLES FROM `` WHERE `Tables_in_` LIKE ‘%cms%‘ OR `Tables_in_` LIKE ‘%role%‘;
#-Bse去除分割符等,,-Dtest可以省略
mysql -uroot -pmysql -Dtest -Bse "show tables from test where tables_in_test like ‘t1%‘ or tables_in_test like ‘t2%‘";
#将上面的结果作为一个Shell的变量传给mysqldump进行批量导出,-Dtest可以省略
mysqldump -uroot -pmysql test $(mysql -uroot -pmysql -Dtest -Bse "show tables from test where tables_in_test like ‘t1%‘ or tables_in_test like ‘t2%‘") > stru.sql