- 背景:因为clickhouse数据持续增加,导致服务器磁盘不够使用,云服务器的系统盘不能扩容,所以只能进行迁移
- 连接clickhouse查看要迁移那些数据库
bash
root@jcdata:~/buckup/clickhouse# clickhouse-client -udefault --password 123456
ClickHouse client version 23.6.2.18 (official build).
Connecting to 192.168.162.5:9000 as user default.
Connected to ClickHouse server version 23.6.2 revision 54464.
jcdata :) show databases
SHOW DATABASES
Query id: 9294909d-88d2-4928-a014-64d49bcd1a3d
┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default │
│ information_schema │
│ system │
│ traffic-axle-load │
└────────────────────┘
6 rows in set. Elapsed: 0.001 sec.
jcdata :) show tables;
SHOW TABLES
Query id: bc6f3e59-49ad-4ff5-91df-7787d341c9b4
┌─name────────────────┐
│ axle_load_atlas │
│ traffic_survey_data │
└─────────────────────┘
2 rows in set. Elapsed: 0.005 sec.
jcdata :)
traffic-axle-load数据库是我要迁移的
- 导出数据
bash
#导出数据1
root@jcdata:~/buckup/clickhouse# clickhouse-client -u default --password=123456 --query "SELECT * FROM \`traffic-axle-load\`.axle_load_atlas" > axle_load_atlas.csv
#导出数据2
root@jcdata:~/buckup/clickhouse# clickhouse-client -u default --password=SHJC666 --query "SELECT * FROM \`traffic-axle-load\`.traffic_survey_data" > traffic_survey_data.csv
- 查看数据导出情况
bash
root@jcdata:~/buckup/clickhouse# ll -h
total 16G
-rw-r--r-- 1 root root 5.5G Aug 13 17:58 axle_load_atlas.csv
-rw-r--r-- 1 root root 10G Aug 13 18:01 traffic_survey_data.csv
#导出完成
- 把数据scp到新的节点
bash
scp -r * root@ip/root/clickhouse/
- 导入数据
我是导入到了同样的数据库不同的数据表、按照研发需求导入,提前创建对应的表、表结构要正确
bash
#导入数据1
[root@sdgs-server01 clickhouse]# clickhouse-client -u admin --password=123456 --query="insert into \`traffic-axle-load\`.axle FORMAT TSV"< axle_load_atlas.csv
#新开一个窗口连接到CK
clickhouse :) select count(*) from axle;
SELECT count(*)
FROM axle
Query id: d41ca2fb-e5a5-4952-b034-deab1ca02413
┌─count()─┐
│ 0 │
└─────────┘
1 row in set. Elapsed: 0.001 sec.
clickhouse :) select count(*) from axle;
SELECT count(*)
FROM axle
Query id: 86c311a0-6a81-48c8-9ce5-90db940c2214
┌──count()─┐
│ 16267692 │
└──────────┘
1 row in set. Elapsed: 0.002 sec.
#通过上面可以看到数据正在导入
#导入数据2
[root@sdgs-server01 clickhouse]# clickhouse-client -u admin --password=123456 --query="insert into \`traffic-axle-load\`.traffic FORMAT TSV"< traffic_survey_data.csv
clickhouse :) select count(*) from traffic;
SELECT count(*)
FROM traffic
Query id: 920e0422-0e66-490c-ba3a-a6665a7c255d
┌─count()─┐
│ 0 │
└─────────┘
1 row in set. Elapsed: 0.001 sec.
clickhouse :) select count(*) from traffic;
SELECT count(*)
FROM traffic
Query id: da399f67-ed7e-4223-8886-115ce60ddf4c
┌─count()─┐
│ 2792470 │
└─────────┘
1 row in set. Elapsed: 0.001 sec.
#此表一样
因为我就两个表,所以只用了clickhouse-client命令完成数据导入和导出