Import mysql database in cockroachDB

cockroachdb

CockroachDB makes scale so simple, you don’t have to think about it. It automatically distributes data and workload demand. Break free from manual sharding and complex workarounds. In this post, you will see how you can import your existing database in cockroachDB.

Take a mysql backup using mysqldump

# mysqldump -uroot -p database > database.sql

gzip the file to compress sql dump

# gzip -9 database.sql

We can import sql.gz file using http, therefore copy the .sql.gz in a web folder.

# mkdir web
# mv database.sql.gz web
# cd web

Start a web server

# python3 -m http.server 8080

Check the service name.

# kubectl get svc -n cockroach

NAME                            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
cockroachdb-1617952308          ClusterIP   None            <none>        26257/TCP,8080/TCP   6h16m
cockroachdb-1617952308-public   ClusterIP   10.43.161.208   <none>        26257/TCP,8080/TCP   6h16m

We need the one with public suffix i.e cockroachdb-1617952308-public , it can be access using cockroachdb-1617952308-public.cockroach.svc.cluster.local

Launch a temporary interactive pod and start the built-in SQL client inside it:

# kubectl run cockroachdb -it --image=cockroachdb/cockroach:v20.2.7 --rm --restart=Never -- sql --insecure --host=cockroachdb-1617952308-public.cockroach.svc.cluster.local
If you don't see a command prompt, try pressing enter.
[email protected]:26257/defaultdb>

Create new database

CREATE DATABASE IF NOT EXISTS database;
USE database;

Import database

IMPORT MYSQLDUMP 'http://192.168.1.10:8080/database.sql.gz';

That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *