Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a tab delimited MySQL dump from a remote host ?

A mysqldump command like the following:

mysqldump -u<username> -p<password> -h<remote_db_host> -T<target_directory> <db_name> --fields-terminated-by=,

will write out two files for each table (one is the schema, the other is CSV table data). To get CSV output you must specify a target directory (with -T). When -T is passed to mysqldump, it writes the data to the filesystem of the server where mysqld is running - NOT the system where the command is issued. Is there an easy way to dump CSV files from a remote system ?

Note: I am familiar with using a simple mysqldump and handling the STDOUT output, but I don't know of a way to get CSV table data that way without doing some substantial parsing. In this case I will use the -X option and dump xml.

like image 412
Ivar Avatar asked Oct 19 '11 11:10

Ivar


Video Answer


1 Answers

mysql -h remote_host -e "SELECT * FROM my_schema.my_table" --batch --silent > my_file.csv
like image 102
codeman Avatar answered Nov 03 '22 01:11

codeman