When using mysqldump
to export MySQL databases, you can control how lines are terminated in the output file using the --lines-terminated-by
option. This option allows you to specify a string that will be appended to the end of each line in the dumped file.
Setting Line Terminator in mysqldump Output:
For example, to set the line terminator to the string “name”, you would use the following command:
mysqldump --lines-terminated-by=name [database_name] > output.sql
This command exports the specified MySQL database to a file named output.sql
, with each line terminated by the string “name”.
Examples:
1. Exporting a database with lines terminated by a semicolon:
mysqldump --lines-terminated-by=";" mydatabase > output.sql
This command exports the database mydatabase
to output.sql
, where each line in the SQL statements is terminated by a semicolon.
2. Exporting a database with lines terminated by a pipe (|):
mysqldump --lines-terminated-by="|" mydatabase > output.sql
This command exports the database mydatabase
to output.sql
, using a pipe (|) as the line terminator.
3. Exporting a database with lines terminated by a specific string “end”:
mysqldump --lines-terminated-by="end" mydatabase > output.sql
This command exports the database mydatabase
to output.sql
, with each line in the file terminated by the string “end”.
Verification Steps:
To verify that the command executed successfully:
- Open the exported file (
output.sql
) using a text editor or command-line tool. - Inspect several lines within the file to confirm that each line ends with the specified terminator string.
By specifying the --lines-terminated-by
option in mysqldump
, you have precise control over the format and termination of lines in the exported SQL or data file, ensuring compatibility with different systems and tools that process the output.
Also check similar articles.
Using INSERT IGNORE Statements in mysqldump
Including Master Host and Port in mysqldump Output (Deprecated)
Including Source Host and Port in mysqldump Output
Ignoring Tables During mysqldump
Ignoring Errors During mysqldump
Discussion about this post