ClickHouse提供了clickhouse-client客戶端可用于數據的快速導入導出
官方文檔: Inserting Data from a File
JSONL 格式
導出
clickhouse-client -h 127.0.0.1 --port 9000 -u default --password XXX -d default \--query "SELECT * from default.doc_type2" --format JSONEachRow > doc_type2.jsonl
導入
clickhouse-client -h 127.0.0.1 --port 9000 -u default --password XXX -d default \--query "INSERT INTO default.doc_type2 FORMAT JSONEachRow" < doc_type2.jsonl
Native 格式
導出
clickhouse-client -h 127.0.0.1 --port 9000 -u default --password XXX -d default \--query "SELECT * from default.doc_type2" --format Native > doc_type2.jsonl
導入
clickhouse-client -h 127.0.0.1 --port 9000 -u default --password XXX -d default \--query "INSERT INTO default.doc_type2 FORMAT Native" < doc_type2.jsonl
對文件夾下的所有文件導入
有時需要導入別人給的幾百個文件,可以選擇使用xargs批量導入
find /home/zlh/xxx_t2/ -type f -print0 | xargs -0 -I {} bash -c 'cat {} | clickhouse-client -h 127.0.0.1 --port 9000 -u default --password XXX -d default --query="INSERT INTO default.doc_type2 FORMAT JSONEachRow"'