Skip to content

Commit 2d02f87

Browse files
github-actions[bot]Chasen-Zhang
authored andcommitted
💬Generate LLM translations
1 parent 7429571 commit 2d02f87

File tree

1 file changed

+216
-0
lines changed

1 file changed

+216
-0
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
---
2+
title: 使用 db-archiver 从 MySQL 迁移
3+
---
4+
5+
在本教程中,我们将指导您如何使用 db-archiver 从 MySQL 迁移到 Databend Cloud。
6+
7+
## 开始之前
8+
9+
在开始之前,请确保您已准备好以下先决条件:
10+
11+
- 本地机器上已安装 [Docker](https://www.docker.com/),因为它将用于启动 MySQL。
12+
- 本地机器上已安装 [Go](https://go.dev/dl/),因为它是安装 db-archiver 所必需的。
13+
- 本地机器上已安装 BendSQL。有关如何使用各种包管理器安装 BendSQL 的说明,请参阅 [安装 BendSQL](/guides/sql-clients/bendsql/#installing-bendsql)
14+
15+
## 第一步:在 Docker 中启动 MySQL
16+
17+
1. 在本地机器上启动一个 MySQL 容器。以下命令启动一个名为 **mysql-server** 的 MySQL 容器,创建一个名为 **mydb** 的数据库,并将 root 密码设置为 `root`
18+
19+
```bash
20+
docker run \
21+
--name mysql-server \
22+
-e MYSQL_ROOT_PASSWORD=root \
23+
-e MYSQL_DATABASE=mydb \
24+
-p 3306:3306 \
25+
-d mysql:8
26+
```
27+
28+
2. 验证 MySQL 是否正在运行:
29+
30+
```bash
31+
docker ps
32+
```
33+
34+
检查输出中是否有一个名为 **mysql-server** 的容器:
35+
36+
```bash
37+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
38+
1a8f8d7d0e1a mysql:8 "docker-entrypoint.s…" 10 hours ago Up About an hour 0.0.0.0:3306->3306/tcp, 33060/tcp mysql-server
39+
```
40+
41+
## 第二步:向 MySQL 中填充示例数据
42+
43+
1. 登录到 MySQL 容器,并在提示时输入密码 `root`
44+
45+
```bash
46+
docker exec -it mysql-server mysql -u root -p
47+
```
48+
49+
```
50+
Enter password:
51+
Welcome to the MySQL monitor. Commands end with ; or \g.
52+
Your MySQL connection id is 8
53+
Server version: 8.4.4 MySQL Community Server - GPL
54+
55+
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
56+
57+
Oracle is a registered trademark of Oracle Corporation and/or its
58+
affiliates. Other names may be trademarks of their respective
59+
owners.
60+
61+
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
62+
```
63+
64+
2. 切换到 **mydb** 数据库:
65+
66+
```bash
67+
mysql> USE mydb;
68+
Database changed
69+
```
70+
71+
3. 复制并粘贴以下 SQL 以创建一个名为 **my_table** 的表并插入数据:
72+
73+
```sql
74+
CREATE TABLE my_table (
75+
id INT AUTO_INCREMENT PRIMARY KEY,
76+
name VARCHAR(255),
77+
value INT
78+
);
79+
INSERT INTO my_table (name, value) VALUES
80+
('Alice', 10),
81+
('Bob', 20),
82+
('Charlie', 30);
83+
```
84+
85+
4. 验证数据:
86+
87+
```bash
88+
mysql> SELECT * FROM my_table;
89+
+----+---------+-------+
90+
| id | name | value |
91+
+----+---------+-------+
92+
| 1 | Alice | 10 |
93+
| 2 | Bob | 20 |
94+
| 3 | Charlie | 30 |
95+
+----+---------+-------+
96+
3 rows in set (0.00 sec)
97+
```
98+
99+
5. 退出 MySQL 容器:
100+
101+
```bash
102+
mysql> quit
103+
Bye
104+
```
105+
106+
## 第三步:在 Databend Cloud 中设置目标
107+
108+
1. 使用 BendSQL 连接到 Databend Cloud。如果您不熟悉 BendSQL,请参考本教程:[使用 BendSQL 连接到 Databend Cloud](../connect/connect-to-databendcloud-bendsql.md)
109+
2. 复制并粘贴以下 SQL 以创建一个名为 **my_table** 的目标表:
110+
111+
```sql
112+
CREATE TABLE my_table (
113+
id INT NOT NULL,
114+
name VARCHAR(255),
115+
value INT
116+
);
117+
```
118+
119+
## 第四步:安装 db-archiver
120+
121+
使用 `go install` 命令安装 db-archiver:
122+
123+
```bash
124+
go install github.com/databend/db-archiver@latest
125+
```
126+
127+
## 第五步:配置并运行 db-archiver
128+
129+
1. 在本地机器上创建一个名为 **conf.json** 的文件,内容如下:
130+
131+
```json
132+
{
133+
// 将占位符替换为您的实际值:
134+
"sourceHost": "127.0.0.1",
135+
"sourcePort": 3306,
136+
"sourceUser": "root",
137+
"sourcePass": "root",
138+
"sourceDB": "mydb",
139+
"sourceTable": "my_table",
140+
"sourceQuery": "select * from mydb.my_table",
141+
"sourceSplitKey": "id",
142+
"sourceWhereCondition": "id < 100",
143+
"databendDSN": "https://cloudapp:{password}@{host}:443?warehouse={warehouse_name}",
144+
"databendTable": "{database}.my_table",
145+
"batchSize": 2,
146+
"batchMaxInterval": 30,
147+
"workers": 1,
148+
"copyPurge": false,
149+
"copyForce": false,
150+
"disableVariantCheck": false,
151+
"deleteAfterSync": false,
152+
"maxThread": 10
153+
}
154+
```
155+
156+
2.**conf.json** 文件所在的目录中运行以下命令以开始迁移:
157+
158+
```bash
159+
db-archiver -f conf.json
160+
```
161+
162+
迁移将按如下方式开始:
163+
164+
```bash
165+
start time: 2025-01-22 21:45:33
166+
sourcedatabase pattern ^mydb$
167+
not match db: information_schema
168+
sourcedatabase pattern ^mydb$
169+
match db: mydb
170+
sourcedatabase pattern ^mydb$
171+
not match db: mysql
172+
sourcedatabase pattern ^mydb$
173+
not match db: performance_schema
174+
sourcedatabase pattern ^mydb$
175+
not match db: sys
176+
INFO[0000] Start worker mydb.my_table
177+
INFO[0000] Worker mydb.my_table checking before start
178+
INFO[0000] Starting worker mydb.my_table
179+
INFO[0000] db.table is mydb.my_table, minSplitKey: 1, maxSplitKey : 6
180+
2025/01/22 21:45:33 thread-1: extract 2 rows (1.997771 rows/s)
181+
2025/01/22 21:45:33 thread-1: extract 0 rows (1.999639 rows/s)
182+
2025/01/22 21:45:33 thread-1: extract 2 rows (1.999887 rows/s)
183+
2025/01/22 21:45:33 thread-1: extract 2 rows (1.999786 rows/s)
184+
INFO[0000] get presigned url cost: 126 ms
185+
INFO[0000] get presigned url cost: 140 ms
186+
INFO[0000] get presigned url cost: 159 ms
187+
INFO[0000] upload by presigned url cost: 194 ms
188+
INFO[0000] upload by presigned url cost: 218 ms
189+
INFO[0000] upload by presigned url cost: 230 ms
190+
INFO[0000] thread-1: copy into cost: 364 ms ingest_databend=IngestData
191+
2025/01/22 21:45:34 thread-1: ingest 2 rows (2.777579 rows/s), 68 bytes (94.437695 bytes/s)
192+
2025/01/22 21:45:34 Globla speed: total ingested 2 rows (2.777143 rows/s), 29 bytes (40.268568 bytes/s)
193+
INFO[0001] thread-1: copy into cost: 407 ms ingest_databend=IngestData
194+
2025/01/22 21:45:34 thread-1: ingest 2 rows (2.603310 rows/s), 72 bytes (88.512532 bytes/s)
195+
2025/01/22 21:45:34 Globla speed: total ingested 4 rows (2.603103 rows/s), 62 bytes (37.744993 bytes/s)
196+
INFO[0001] thread-1: copy into cost: 475 ms ingest_databend=IngestData
197+
2025/01/22 21:45:34 thread-1: ingest 2 rows (2.401148 rows/s), 70 bytes (81.639015 bytes/s)
198+
2025/01/22 21:45:34 Globla speed: total ingested 6 rows (2.400957 rows/s), 93 bytes (34.813873 bytes/s)
199+
INFO[0001] Worker dbarchiver finished and data correct, source data count is 6, target data count is 6
200+
end time: 2025-01-22 21:45:34
201+
total time: 1.269478875s
202+
```
203+
204+
3. 返回到您的 BendSQL 会话并验证迁移:
205+
206+
```sql
207+
SELECT * FROM my_table;
208+
209+
┌────────────────────────────────────────────┐
210+
│ id │ name │ value │
211+
├───────┼──────────────────┼─────────────────┤
212+
3 │ Charlie │ 30
213+
1 │ Alice │ 10
214+
2 │ Bob │ 20
215+
└────────────────────────────────────────────┘
216+
```

0 commit comments

Comments
 (0)