Using MySQL as a starting point, this guide demonstrates how to migrate your existing data from SQL tables to a Couchbase Capella instance.
In this tutorial,
you will make use of cbimport
to migrate an example test database from MySQL to Couchbase Capella.
Before you make a start, you will need a Capella instance to run the tutorial. If you do not currently have an instance, then you can create a Capella trial here ⇒ Capella Trial
You will also need to download and install the Server Development Tools package,
which includes the cbimport
command line application.
You will find installation instructions for the Server Development Tools package here ⇒ Server Development Tools package
If you’re running through the examples, then you will also need an existing MySQL installation with the preexisting table structure defined in the following section.
Important
|
This tutorial makes use of the MySQL JSON functions that were introduced in version 5.7.22 .
Make sure you have installed MySQL version 5.7.22 or later.
|
Working on your Capella instance, you must first create the cluster (or use an existing cluster if you have one available). We will assume that you are creating a cluster from scratch. You will also need to create the bucket, scope, and collections to accept the student data.
-
Sign in to your Capella instance. You will be presented showing the operational clusters along with the project that the cluster is attached to.
-
Press the btn:[Create Cluster] button.
-
Now create a new project with a name of your choice.
-
You will now be given the opportunity to create a new cluster which will be attached to your project. For this exercise, we’re going to create a new project for our data migration, so click on the link to take you to the Project list.
-
Press the btn:[Create Project] button on the top right of the list. This will take you to a dialog from where you can fill in the name of your new project.
-
Enter a name for your project, then press btn:[Create Project]
-
Capella will create a new project for you and then switch back to the Project List. You can navigate to your project by clicking on the link in the top left of the screen.
TipYou can also navigate to your project by finding it in the Project List and clicking on its link. -
On your project page, click on btn:[Create Cluster]
-
Select your cluster options (you may use the free option if it’s available), then press btn:[Create Cluster].
After a short interval, your new cluster will be provisioned.
Now that we have created the cluster, we need to add a location to hold the migrated data.
-
Click on the name of your cluster from the Operational Clusters page. This will take you to the Cluster details page.
-
From here, click on the btn:[Import Data] button. This will take you to the menu:Data Tools[] page.
-
Select btn:[Load with cbimport] in the central panel.
-
Click on the btn:[+Create] button in the panel on the left. You will now be presented with a dialog for creating a bucket.
-
Fill in
student-bucket
for the name of your bucket. -
Fill in
art-school-scope
for the scope. -
Fill in
student-record-collection
for the collection inside the scope. -
Click on btn:[Create]
-
We still need to create another collection to hold the course records, so press btn:[+Create] again.
-
Make sure that you are adding to an existing bucket (
student-bucket
) and scope (art-school-scope
). Now add another collection:course-record-collectiomn
.
Before running cbimport
from your local machine,
you need to add your machine’s IP address to Capella’s allowed list.
Navigate to your cluster’s security settings and add your IP to the "Allowed IP addresses" list.
-
Click on menu:Settings[] from the top level menu.
-
From the left-hand menu, select menu:Networking[Allowed IP Addresses]
-
Click the btn:[+ Add Allowed IP] button.
-
From the menu:Allowed IP[] screen, click on btn:[Add Current IP address], then click btn:[Add Allowed IP]
When running cbimport
, authentication credentials are required, which you can set up
from menu:Security[] in Capella.
-
From the menu:Settings[] page, select menu:Security[Cluster Access]
-
Click on the btn:[+ Create Cluster Access] button.
-
Type
import
into theCluster Access Name
field with. -
Add a password.
-
In the
Bucket Level Access
section, selectstudent-bucket
for the bucket,All Scopes
for the scope, andRead/Write
for Access: -
Click on btn:[Create Cluster Access] when you’re done.
To run cbimport
, you will need to supply the security certificate for your Capella instance,
which you can download from the menu:settings[] page.
-
From the top menu, click on menu:Settings[]
-
Now, from the menu:Cluster Settings[] screen, click on menu:Security[Security Certificates] in the left-hand menu.
-
On the menu:Security Certificate[] page, click on btn:[Download] to download your security certificate for the local machine.
TipMake a note of the location where you stored it. -
Return to the menu:Data Tools[] page by clicking on the link in the top level menu.
The data tooling page can generate a correctly formatted cbimport
command line based on your import data.
All you need to do is copy the command to your command line environment
and fill in details such as your access password and the location of your security certificate.
cbimport
command.-
From the menu:Data Tools[] page, click on btn:[Load with cbimport] in the central panel.
-
Locate the
courses
JSON file you created in the [extract-sql-data] section, then drag it into theUpload Sample File
section in the central panel.TipAlternatively, you can click on Choose a file
and load the file directly from the file chooser. -
In the
Choose your target
section, select thestudent-bucket
,art-school-scope
, and thecourse-record-collection
. -
For
Document keys
, selectField
, then pick thecourse-id
field from the dropdown list.
The Copy generated command
field will contain the cbimport
statement you will need to execute the import:
cbimport
commandcbimport json --format lines --cluster couchbases://cb.wrrmzje92urkkyn.customsubdomain.nonprod-project-avengers.com --username <<username>> --password '<<password>>' --bucket "student-bucket" --scope-collection-exp "art-school-scope.course-record-collection" --dataset 'file://<<path>>/courses.json' --generate-key '%`course-id`%' --cacert <<path to downloaded cert file>>
Before you can run the command, you will need to fill in the placeholders with information from your cluster:
-
Username and password. These are the details you created in the Set up cluster access credentials section.
-
the full path to your input source (
courses.json
) -
the full path to your downloaded security certificate, which you downloaded in the Download your security certificate section.
Your command should resemble the following:
./cbimport json --format lines \
--cluster couchbases://cb.wrrmzje92urkkyn.customsubdomain.nonprod-project-avengers.com \
--username import --password 'Password' \
--bucket "student-bucket" --scope-collection-exp "art-school-scope.course-record-collection" \
--dataset 'file:///Users/test/courses.json' \
--generate-key '%`course-id`%' \
--cacert /Users/test/Cluster-1-root-certificate.txt
You can repeat the same process to generate and run a cbimport
command for the students.json
file.
Remember to:
-
Change the
--scope-collection-exp
parameter to point toart-school-scope.student-record-collection
. -
Set the
--dataset
parameter to point to thestudents.json
file. -
Set the
--generate-key
parameter to'%`course-id`%'