You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this tutorial, you will set up a real-time data loading from MySQL to Databend with the Flink SQL connector for Databend. Before you start, make sure you have successfully set up Databend and MySQL in your environment.
5
+
In this tutorial, we'll walk you through the process of migrating from MySQL to Databend Cloud using Apache Flink CDC.
6
6
7
-
1. Create a table in MySQL and populate it with sample data. Then, create a corresponding target table in Databend.
7
+
## Before You Start
8
8
9
-
```sql title='In MySQL:'
10
-
CREATEDATABASEmydb;
11
-
USE mydb;
9
+
Before you start, ensure you have the following prerequisites in place:
12
10
11
+
-[Docker](https://www.docker.com/) is installed on your local machine, as it will be used to launch MySQL.
12
+
- Java 8 or 11 is installed on your local machine, as it is required by the [Flink Databend Connector](https://github.com/databendcloud/flink-connector-databend).
13
+
- BendSQL is installed on your local machine. See [Installing BendSQL](/guides/sql-clients/bendsql/#installing-bendsql) for instructions on how to install BendSQL using various package managers.
14
+
15
+
## Step 1: Launch MySQL in Docker
16
+
17
+
1. Create a configuration file named **mysql.cnf** with the following content, and save this file in a local directory that will be mapped to the MySQL container, e.g., `/Users/eric/Downloads/mysql.cnf`:
2. Start a MySQL container on your local machine. The command below launches a MySQL container named **mysql-server**, creates a database named **mydb**, and sets the root password to `root`:
2. Download [Flink](https://flink.apache.org/downloads/) and the following SQL connectors to your system:
33
-
- Flink SQL connector for Databend: [https://github.com/databendcloud/flink-connector-databend/releases](https://github.com/databendcloud/flink-connector-databend/releases)
34
-
- Flink SQL connector for MySQL: [https://repo1.maven.org/maven2/com/ververica/flink-sql-connector-mysql-cdc/2.3.0/flink-sql-connector-mysql-cdc-2.3.0.jar](https://repo1.maven.org/maven2/com/ververica/flink-sql-connector-mysql-cdc/2.3.0/flink-sql-connector-mysql-cdc-2.3.0.jar)
35
-
3. Move the both connector JAR files to the _lib_ folder in your Flink installation directory.
36
-
4. Start Flink:
133
+
## Step 3: Set Up Target in Databend Cloud
134
+
135
+
1. Connect to Databend Cloud using BendSQL. If you're unfamiliar with BendSQL, refer to this tutorial: [Connecting to Databend Cloud using BendSQL](../connect/connect-to-databendcloud-bendsql.md).
136
+
137
+
2. Copy and paste the following SQL to create a target table named **products**:
3. Open the file **flink-conf.yaml** under `flink-1.17.1/conf/`, update `taskmanager.memory.process.size` to `4096m`, and save the file.
166
+
167
+
```yaml
168
+
taskmanager.memory.process.size: 4096m
169
+
```
170
+
171
+
4. Start a Flink cluster:
37
172
38
173
```shell
39
-
cd flink-16.0
40
174
./bin/start-cluster.sh
41
175
```
42
176
43
177
You can now open the Apache Flink Dashboard if you go to [http://localhost:8081](http://localhost:8081) in your browser:
44
178
45
179

46
180
47
-
5. Start the Flink SQL Client:
181
+
## Step 5: Start Migration
48
182
49
-
```shell
183
+
1. Start the Flink SQL Client:
184
+
185
+
```bash
50
186
./bin/sql-client.sh
187
+
```
188
+
189
+
You will see the Flink SQL Client startup banner, confirming that the client has launched successfully.
190
+
191
+
```bash
51
192
52
193
▒▓██▓██▒
53
194
▓████▒▒█▓▒▓███▓▒
@@ -92,49 +233,98 @@ You can now open the Apache Flink Dashboard if you go to [http://localhost:8081]
92
233
Welcome! Enter 'HELP;' to list all available commands. 'QUIT;' to exit.
93
234
```
94
235
95
-
6. Set the checkpointing interval to 3 seconds, and create corresponding tables with MySQL and Databend connectors in the Flink SQL Client. For the available connection parameters, see [https://github.com/databendcloud/flink-connector-databend#connector-options](https://github.com/databendcloud/flink-connector-databend#connector-options):
236
+
2. Set the checkpointing interval to 3 seconds.
96
237
97
-
```sql
238
+
```bash
98
239
Flink SQL> SET execution.checkpointing.interval = 3s;
99
-
[INFO] Session property has been set.
240
+
```
100
241
101
-
Flink SQL> CREATE TABLE mysql_products (id INT,name STRING,description STRING,PRIMARY KEY (id) NOT ENFORCED)
242
+
3. Create corresponding tables with MySQL and Databend connectors in the Flink SQL Client (replace the placeholders with your actual values):
243
+
244
+
```sql
245
+
CREATE TABLE mysql_products (id INT,name STRING,description STRING,PRIMARY KEY (id) NOT ENFORCED)
102
246
WITH ('connector' = 'mysql-cdc',
103
-
'hostname'='localhost',
247
+
'hostname' = '127.0.0.1',
104
248
'port' = '3306',
105
249
'username' = 'root',
106
-
'password'='123456',
250
+
'password' = 'root',
107
251
'database-name' = 'mydb',
108
252
'table-name' = 'products',
109
253
'server-time-zone' = 'UTC'
110
254
);
111
-
[INFO] Execute statement succeed.
112
255
113
-
Flink SQL>CREATE TABLE databend_products (id INT,name String,description String, PRIMARY KEY (`id`) NOT ENFORCED)
256
+
CREATE TABLE databend_products (id INT,name String,description String, PRIMARY KEY (`id`) NOT ENFORCED)
7. In the Flink SQL Client, synchronize the data from the _mysql_products_ table to the _databend_products_ table:
267
+
4. In the Flink SQL Client, synchronize the data from the mysql_products table to the databend_products table:
128
268
129
269
```sql
130
270
Flink SQL> INSERT INTO databend_products SELECT * FROM mysql_products;
271
+
>
131
272
[INFO] Submitting SQL update statement to the cluster...
132
273
[INFO] SQL update statement has been successfully submitted to the cluster:
133
-
Job ID: b14645f34937c7cf3672ffba35733734
274
+
Job ID: 5b505d752b7c211cbdcb5566175b9182
134
275
```
135
276
136
277
You can now see a running job in the Apache Flink Dashboard:
137
278
138
279

139
280
140
-
You're all set! If you query the _products_ table in Databend, you will see that the data from MySQL has been successfully synchronized. Feel free to perform insertions, updates, or deletions in MySQL, and you will observe the corresponding changes reflected in Databend as well.
281
+
You're all set! If you go back to the BendSQL terminal and query the **products** table in Databend Cloud, you will see that the data from MySQL has been successfully synchronized:
0 commit comments