Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing from MySQL dump to Clickhouse

I want to import from MySQL dump to Clickhouse. I've tried going through the official docs but cannot find anything. I've tried importing using CSV following Stack Overflow answer. Any help appreciated. I've an Ubuntu 16.04 LTS.

like image 843
Niyanta Avatar asked Dec 08 '17 05:12

Niyanta


People also ask

How does ClickHouse integrate with MySQL?

Using MySQL protocol and MySQL client to connect to ClickHouse. Use MySQL tables to select and join with ClickHouse tables.

How do I import a SQL dump into Sequel Pro?

sql file for use with my database? To import an SQL dump file using the most recent version of Sequel Pro, connect to your MySQL host and select a database, then choose 'Import...' from the File menu.


2 Answers

On small data, the export to tsv will work but at large it will not work, because only export will take a lot of time.

In this case, you need to import directly from stdout and clickhouse knows how to do it perfectly.

Example code:

mysql -u user  -ppass --compress -ss -e "SELECT * FROM table WHERE id >0  AND id <=1000000" db_name | sed 's/\"//g;s/\t/","/g;s/^/"/;s/$/"/' | clickhouse-client --query="INSERT INTO db_name.table FORMAT CSV"

Using this method, I import 500 GB and 1,9 billion rows in 7-10 hours in a clickhouse

like image 93
Evgeny Shevtsov Avatar answered Oct 04 '22 17:10

Evgeny Shevtsov


You can export data from MySQL into TSV file using MySQL command line:

mysql -Bse "select * from TABLE_NAME" > table.tsv

And then import data to ClickHouse:

cat table.tsv | clickhouse-client --query="INSERT INTO TABLE_NAME FORMAT TabSeparated"
like image 26
Mikhail Avatar answered Oct 04 '22 17:10

Mikhail