StarRocks数据导入、导出

# 导入测试数据
mysql -h10.2.30.28 -P9030 -uadmin -pchengce243  testdb -A

create database testdb;
use testdb;

CREATE TABLE IF NOT EXISTS detail (
    event_time DATETIME NOT NULL COMMENT "datetime of event",
    event_type INT NOT NULL COMMENT "type of event",
    user_id INT COMMENT "id of user",
    device_code INT COMMENT "device code",
    channel INT COMMENT ""
)
DUPLICATE KEY(event_time, event_type)
DISTRIBUTED BY HASH(user_id)
PROPERTIES (
"replication_num" = "1"
);
  
  
insert into detail  select "2023-12-06",1,980500,123,321;
insert into detail  select "2023-12-06",1,980501,123,321;
insert into detail  select "2023-12-06",1,980502,123,321;
insert into detail  select "2023-12-06",1,980503,123,321;
insert into detail  select "2023-12-06",1,980504,123,321;



导出CSV:
mysql -h10.2.30.28 -P9030 -uadmin -pchengce243  testdb  -e "select * from detail" -s |sed -e  "s/\t/,/g" -e "s/NULL/  /g" -e "s/\n/\r\n/g"  >  detail.csv


CSV导入:

use testdb;

CREATE TABLE IF NOT EXISTS detail2 (
    event_time DATETIME NOT NULL COMMENT "datetime of event",
    event_type INT NOT NULL COMMENT "type of event",
    user_id INT COMMENT "id of user",
    device_code INT COMMENT "device code",
    channel INT COMMENT ""
)
DUPLICATE KEY(event_time, event_type)
DISTRIBUTED BY HASH(user_id)
PROPERTIES (
"replication_num" = "1"
);


curl --location-trusted -u admin:chengce243  \
    -H "Expect:100-continue" \
    -H "column_separator:," \
    -H "columns: event_time, event_type, user_id, device_code, channel" \
    -T detail.csv -XPUT \
    http://10.2.30.28:8030/api/testdb/detail2/_stream_load
    
    
    

 

posted @ 2025-06-18 00:10  屠魔的少年  阅读(37)  评论(0)    收藏  举报