How to get tab dump delimited MySQL from remote host?

The mysqldump command looks like this:

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

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

Note. I am familiar with using simple mysqldump and handling the output of STDOUT, but I don’t know how to get CSV table data in this way without doing significant analysis. In this case, I will use the -X option and dump xml.

+5
source share
3 answers
mysql -h remote_host -e "SELECT * FROM my_schema.my_table" --batch --silent > my_file.csv
+10
source

I want to add to the defendant. It worked, but it took me about 30 minutes to configure for my needs.

My web server uses centos 6 / cpanel, and the flags and sequence used above did not help me, and I had to reorder and use different flags, etc.

In addition, I used this to dump the file locally, which is not only useful for remote databases, because I had too many problems with selinux and mysql user rights for SELECT INTO OUTFILE commands, etc.

What worked on my Centos + Cpanel server

mysql -B -s -uUSERNAME -pPASSWORD < query.sql > /path/to/myfile.txt

Warnings

No column names

I cannot get the column names at the top. I tried to add a flag:

--column-names

. . .

- .

-D databasename

, , query.sql:

USE database_name;
+2

MySQL (, "mysql" ), mysqldump , MySQL - , . ( ) , (777), .

+1

All Articles