The mysqldump
command in MySQL is used to create backups of MySQL databases, allowing you to dump the entire database or specific tables into a file. One useful option is --fields-enclosed-by=name
, which specifies how fields in the output should be enclosed. This option is particularly handy when exporting data that contains special characters or delimiter conflicts.
Here are several examples illustrating the use of --fields-enclosed-by=name
:
Example 1: Enclosing fields with double quotes:
mysqldump --fields-enclosed-by='"' --tab=/path/to/dump/directory dbname tablename
This command exports the table tablename
from the database dbname
and encloses each field in double quotes. To verify if the command executed successfully, check the dump directory for the presence of a file containing the dumped data.
Example 2: Enclosing fields with square brackets:
mysqldump --fields-enclosed-by='[' --tab=/path/to/dump/directory dbname tablename
This command exports the same table but encloses each field in square brackets. Check the dump directory similarly for the output file to verify execution.
Example 3: Enclosing fields with backticks:
mysqldump --fields-enclosed-by='`' --tab=/path/to/dump/directory dbname tablename
Here, each field is enclosed with backticks. Ensure to inspect the dump directory to confirm the creation of the dump file.
Example 4: Enclosing fields with single quotes:
mysqldump --fields-enclosed-by="'" --tab=/path/to/dump/directory dbname tablename
This command uses single quotes to enclose fields. Verify the output file in the specified dump directory after execution.
Example 5: Enclosing fields with angle brackets:
mysqldump --fields-enclosed-by='<' --tab=/path/to/dump/directory dbname tablename
In this case, fields are enclosed with angle brackets. Check the dump directory for the exported data file.
Example 6: Enclosing fields with curly braces:
mysqldump --fields-enclosed-by='{' --tab=/path/to/dump/directory dbname tablename
Here, each field is enclosed with curly braces. Verify the dumped file in the directory specified.
Example 7: Enclosing fields with parentheses:
mysqldump --fields-enclosed-by='(' --tab=/path/to/dump/directory dbname tablename
This command uses parentheses to enclose fields. Check the dump directory for the output file to confirm execution.
Example 8: Enclosing fields with pipes:
mysqldump --fields-enclosed-by='|' --tab=/path/to/dump/directory dbname tablename
Fields are enclosed with pipes in this example. Verify the dump directory for the exported data file.
Example 9: Enclosing fields with square brackets and a specific delimiter:
mysqldump --fields-enclosed-by='[' --fields-terminated-by=',' --tab=/path/to/dump/directory dbname tablename
This command not only encloses fields with square brackets but also specifies a comma (,) as the field delimiter. Check the dump directory for both the format and the delimiter in the dumped file.
Example 10: Enclosing fields with double quotes and including column headers:
mysqldump --fields-enclosed-by='"' --complete-insert --tab=/path/to/dump/directory dbname tablename
Here, fields are enclosed in double quotes, and --complete-insert
includes column headers in the dump. Verify the dump directory for the file containing the dumped data with headers.
Also check similar articles.
Setting Field Terminator in mysqldump Output
Using Extended INSERT Syntax in mysqldump
Dumping Events Using mysqldump
Dumping Slave Position in mysqldump Output (Deprecated)
Dumping Replica Position in mysqldump Output
Discussion about this post