mysql从一个库的一个表中导出select部分内容的数据,将其导入到另外一个库的同结构的表中

首先查询mysql 导出指定的路径,使用命令

    show variables like '%secure%'; 

比如我的查询结果为

Variable_name       Value
secure_auth       ON
secure_file_priv      /var/lib/mysql-files/

那么应该使用路径 /var/lib/mysql-files/

例如:

SELECT a.dic_id, a.`name`, a.`value`, a.state, a.order_num FROM (
SELECT dic_id, `name`, `value`, state, order_num FROM tbl_dict_item WHERE dic_id ='res_level'
UNION SELECT dic_id, `name`, `value`, state, order_num FROM tbl_dict_item WHERE dic_id ='res_4'
UNION SELECT dic_id, `name`, `value`, state, order_num FROM tbl_dict_item WHERE dic_id ='res_2'
UNION SELECT dic_id, `name`, `value`, state, order_num FROM tbl_dict_item WHERE dic_id ='res_5'
UNION SELECT dic_id, `name`, `value`, state, order_num FROM tbl_dict_item WHERE dic_id ='res_11'
UNION SELECT dic_id, `name`, `value`, state, order_num FROM tbl_dict_item WHERE dic_id ='res_6') a
INTO OUTFILE '/var/lib/mysql-files/aa.sql';

导入使用命令:

load data local infile "/var/lib/mysql-files/aa.sql" into table tbl_dict_item character set utf8;

原文地址:https://www.cnblogs.com/littleapple/p/10911996.html