doris export导出和导入

 

 

 

#################################################导出#####################################

每个be节点都要创建好导出目录,因为导出任务是具体落在某个be上执行的
mkdir /tmp/export_tb_hxl/

 

1.导出表--带字段名称

通过连接fe导出

/opt/mysql5744/bin/mysql -uroot -P9030 -h 192.168.1.134 -pmysql

EXPORT TABLE db_test.tb_hxl
TO "file:///tmp/export_tb_hxl/"
PROPERTIES (
    "label" = "export_tb_hxl_01",
    "format" = "csv_with_names",
    "column_separator" = "€"
);

label名称自定义

 

2.导出表--不带字段名称

EXPORT TABLE db_test.tb_hxl
TO "file:///tmp/export_tb_hxl/"
PROPERTIES (
    "label" = "export_tb_hxl_07",
    "format" = "csv",
    "column_separator" = "€"
);

 

导出时进行压缩

 

EXPORT TABLE db_test.tb_hxl
TO "file:///tmp/export_tb_hxl/tb_hxl_"
PROPERTIES (
    "label" = "export_tb_hxl_01",
    "format" = "csv_with_names",
    "column_separator" = "€",
    "compress_type" = "gz"
);

 

 

 

 

3.查看导出的文件落在那个be节点上

mysql> use db_test
mysql> SHOW EXPORT;
+---------------+---------------------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+---------------------+---------------------+---------------------+---------+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| JobId         | Label                                       | State    | Progress | TaskInfo                                                                                                                                                                                                                                                  | Path                           | CreateTime          | StartTime           | FinishTime          | Timeout | ErrorMsg | OutfileInfo                                                                                                                                                                               |
+---------------+---------------------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+---------------------+---------------------+---------------------+---------+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 1792653459576 | export_tb_test_02                           | FINISHED | 100%     | {"partitions":[],"parallelism":1,"data_consistency":"partition","format":"csv","broker":"local","column_separator":"€","line_delimiter":"\n","max_file_size":"","delete_existing_files":"","with_bom":"false","db":"db_test","tbl":"tb_test"}             | file:///tmp/export_tb_test_all | 2026-10-22 15:52:09 | 2026-10-22 15:52:10 | 2026-10-22 15:52:10 | 7200    | NULL     | [[{"fileNumber":"1","totalRows":"3","fileSize":"30","url":"file:///192.168.1.134/tmp/export_tb_test_allbe87a791d9334b46-9841b9f402231319_*","writeTime":"0.000","writeSpeed":"388.14"}]]  |
+---------------+---------------------------------------------+----------+----------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------+---------------------+---------------------+---------------------+---------+----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
3 rows in set (0.01 sec)

查看具体某个任务
mysql> SHOW EXPORT WHERE LABEL="export_tb_hxl_07"\G
*************************** 1. row ***************************
      JobId: 1792653459948
      Label: export_tb_hxl_07
      State: FINISHED
   Progress: 100%
   TaskInfo: {"partitions":[],"parallelism":1,"data_consistency":"partition","format":"csv","broker":"local","column_separator":"€","line_delimiter":"\n","max_file_size":"","delete_existing_files":"","with_bom":"false","db":"db_test","tbl":"tb_hxl"}
       Path: file:///tmp/export_tb_hxl/
 CreateTime: 2026-10-22 17:07:37
  StartTime: 2026-10-22 17:07:37
 FinishTime: 2026-10-22 17:07:41
    Timeout: 7200
   ErrorMsg: NULL
OutfileInfo: [[{"fileNumber":"1","totalRows":"1000000","fileSize":"140888495","url":"file:///192.168.1.113/tmp/export_tb_hxl/7a83a54ead8a4e64-bbb07d0c5970bd94_*","writeTime":"3.052","writeSpeed":"45078.53"}]]
1 row in set (0.01 sec)

文件落在如下的be节点的如下目录
file:///192.168.1.113/tmp/export_tb_hxl

 

#############################################导入########################################

登录到文件存放的be服务器,在linux终端执行如下命令

curl --location-trusted -u root:mysql \
-H "label:stream_load_tb_hxl_01" \
-H "format:csv" \
-H "column_separator:€" \
-H "max_filter_ratio:0.0" \
-T /tmp/export_tb_hxl/7a83a54ead8a4e64-bbb07d0c5970bd94_0.csv \
http://192.168.1.113:8030/api/db_test/tb_hxl/_stream_load

这里链接的是fe的地址:192.168.1.113:8030

 

同时可以导入到mysql

1.mysql端建表

在mysql端创建与doris结构一致的表

/opt/mysql57/bin/mysql -h localhost -uroot -pyeemiao1117 -S /opt/mysql57/data/mysql.sock
use db_test;
CREATE TABLE tb_hxl (
    id bigint NOT NULL COMMENT "id",
    name1 VARCHAR(20),
    name2 VARCHAR(20),
    name3 VARCHAR(20),
    name4 VARCHAR(20),
    name5 VARCHAR(20),
    name6 VARCHAR(20),
    name7 VARCHAR(20),
    name8 VARCHAR(20),
    name9 VARCHAR(20),
    name10 VARCHAR(20),
    create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB COMMENT='doris数据导入';

 

2.将doris导出的文件上传到mysql服务器secure_file_priv参数指定的目录
[root@host113 export_tb_hxl]# scp 7a83a54ead8a4e64-bbb07d0c5970bd94_0.csv root@192.168.1.14:/opt/mysql57/secure_file/

 

3.登录mysql服务器执行如下导入命令

/opt/mysql57/bin/mysql -h localhost -uroot -pyeemiao1117 -S /opt/mysql57/data/mysql.sock
use db_test
LOAD DATA INFILE '/opt/mysql57/secure_file/7a83a54ead8a4e64-bbb07d0c5970bd94_0.csv' INTO TABLE tb_hxl
FIELDS TERMINATED BY '€' ENCLOSED BY '"'
LINES TERMINATED BY '\n';

 

posted @ 2026-10-22 17:17  slnngk  阅读(9)  评论(0)    收藏  举报