I'm trying to do this:
mysql -u root old_db -e "SELECT some_fields FROM huge_table INTO OUTFILE ..." \
| cat header.sql - trailer.sql \
| psql new_db
Where header.sql contains:
COPY huge_table (some_fields) FROM stdin;
And trailer.sql just contains the \.
to terminate the stream.
I can't for the life of me figure out how to get MySQL to dump tab-separated values into STDOUT so that this pipe can work. I've tried specifying /dev/stdout as the path, but it claims to not have permission.
I'm trying to do this to get the data from MySQL to PostgreSQL as fast as possible. The time to write to disk and back into PostgreSQL is too slow.
I notice that if you pipe a query into MySQL it almost outputs a TSV, but not quite.
Is there any way to do this or am I flogging a dead horse?