cockroachdb / docs

CockroachDB user documentation
https://cockroachlabs.com/docs
Creative Commons Attribution 4.0 International
189 stars 459 forks source link

CockroachDB export for importing into MySQL and Postgres #3540

Open robert-s-lee opened 6 years ago

robert-s-lee commented 6 years ago

Exalate commented:

A bit more content for https://www.cockroachlabs.com/docs/v2.1/export.html#main-content

Not all databases honor properly formatted CSV file CockroachDB produces. Most common issues are delimiter that is embedded inside a quote string. For example, it is common to have , and tab characters as a part of string. MySQL and Postgres also expect NULL to be represented as \N. For the delimiter, a common alternate character is HEX x01. Below examples exports from CockroachDB using the HEX x01 as delimiter and \N as NULL:

EXPORT INTO CSV 'nodelocal:////dirname' WITH delimiter = e'\x01', nullas = '\N' from table tablename;

Import into Postgres:

echo "copy tablename from stdin with DELIMITER e'\x01';" | cat - n1.0.csv | psql

Import into MySQL:

load data local infile 'n1.0.csv' into table tablename FIELDS terminated by X'01' | mysql --local-infile database_name

Jira Issue: DOC-183

jseldess commented 6 years ago

Thanks, @robert-s-lee. I'm not clear on what exactly you'd like us to add, though. Can you summarize?

robert-s-lee commented 6 years ago

cockroachDB import and export commands work with Common Format and MIME Type for Comma-Separated Values (CSV) Files. MySQL and Postgres do not. In order for CockroachDB export CSV to be useable by MySQL and Postgres, special delimiter and specific NULL convention have to be followed. The examples provide the instructions.

jseldess commented 5 years ago

@robert-s-lee, just revisiting this. Why would we want to document how to migrate data from cockroach to mysql/postrgres?

MattFellows commented 5 years ago

@jseldess I guess it might just be a nice thing to do? :) Alternatively people might want to interchange technologies for many reasons. If Cockroach becomes a black hole (importing data, but not exporting in a useful format) people might refrain from using it.

jseldess commented 2 years ago

We have closed this issue because it is more than 3 years old. If this issue is still relevant, please add a comment and reopen the issue. Thank you for your contribution to CockroachDB docs!

Inigo4562 commented 2 years ago

This was actually very useful. I took some time to find so I think it could really help including it in the main docs

exalate-issue-sync[bot] commented 2 years ago

Kathryn Hancox (kathancox) commented: Ryan Kuo This is a really old issue. I think it would fall under your area now? Do you know if this can actually be closed?

exalate-issue-sync[bot] commented 2 years ago

Ryan Kuo (taroface) commented: Kathryn Hancox I’ll assign it to myself! Thanks.

Placing it in Migrations but I’m not sure how much this applies to the area.

drnachio commented 1 year ago

We need to be able to do it or we will need to move to other DB

awoods187 commented 1 year ago

@drnachio can you say more about what functionality/goal you need to solve?