Change the column data delimiter on mysqldump output
I'm looking to change to formatting of the output produced by the mysqldump command in the following way:
(data_val1,data_val2,data_val3,...)
to
(data_val1|data_val2|data_val3|...)
The change here being a different delimiter. This would then allow me to (in python) parse the data lines using a line.split("|") command and end up with the values correctly split (as opposed to doing line.split(",") and have values that contain commas be split into multiple values).
I've tried using the --fields-terminated-by flag, but this requires the --tab flag to be used as well. I don't want use the --tab flag as it splits the dump into seve开发者_如何学运维ral files. Does anyone know how to alter the delimiter that mysqldump uses?
This is not a good idea. Instead of using string.split()
in Python, use the csv
module to properly parse CSV data, which may be enclosed in quotes and may have internal ,
which aren't delimiters.
import csv
MySQL dump files are intended to be used as input back into MySQL. If you really want pipe-delimited output, use the SELECT INTO OUTFILE
syntax instead with the FIELDS TERMINATED BY '|'
option.
精彩评论