Rechercher dans le manuel MySQL
7.4.3 Dumping Data in Delimited-Text Format with mysqldump
This section describes how to use mysqldump to create delimited-text dump files. For information about reloading such dump files, see Section 7.4.4, “Reloading Delimited-Text Format Backups”.
If you invoke mysqldump with the
--tab=
option, it uses dir_name
dir_name
as the
output directory and dumps tables individually in that directory
using two files for each table. The table name is the base name
for these files. For a table named t1
, the
files are named t1.sql
and
t1.txt
. The .sql
file
contains a CREATE TABLE
statement
for the table. The .txt
file contains the
table data, one line per table row.
The following command dumps the contents of the
db1
database to files in the
/tmp
database:
- shell> mysqldump --tab=/tmp db1
The .txt
files containing table data are
written by the server, so they are owned by the system account
used for running the server. The server uses
SELECT ... INTO
OUTFILE
to write the files, so you must have the
FILE
privilege to perform this
operation, and an error occurs if a given
.txt
file already exists.
The server sends the CREATE
definitions for
dumped tables to mysqldump, which writes them
to .sql
files. These files therefore are
owned by the user who executes mysqldump.
It is best that --tab
be used
only for dumping a local server. If you use it with a remote
server, the --tab
directory
must exist on both the local and remote hosts, and the
.txt
files will be written by the server in
the remote directory (on the server host), whereas the
.sql
files will be written by
mysqldump in the local directory (on the
client host).
For mysqldump --tab, the server by default
writes table data to .txt
files one line
per row with tabs between column values, no quotation marks
around column values, and newline as the line terminator. (These
are the same defaults as for
SELECT ... INTO
OUTFILE
.)
To enable data files to be written using a different format, mysqldump supports these options:
The string for separating column values (default: tab).
The character within which to enclose column values (default: no character).
--fields-optionally-enclosed-by=
char
The character within which to enclose non-numeric column values (default: no character).
The character for escaping special characters (default: no escaping).
The line-termination string (default: newline).
Depending on the value you specify for any of these options, it
might be necessary on the command line to quote or escape the
value appropriately for your command interpreter. Alternatively,
specify the value using hex notation. Suppose that you want
mysqldump to quote column values within
double quotation marks. To do so, specify double quote as the
value for the
--fields-enclosed-by
option. But this character is often special to command
interpreters and must be treated specially. For example, on
Unix, you can quote the double quote like this:
--fields-enclosed-by='"'
On any platform, you can specify the value in hex:
--fields-enclosed-by=0x22
It is common to use several of the data-formatting options
together. For example, to dump tables in comma-separated values
format with lines terminated by carriage-return/newline pairs
(\r\n
), use this command (enter it on a
single line):
shell> mysqldump --tab=/tmp --fields-terminated-by=,
--fields-enclosed-by='"' --lines-terminated-by=0x0d0a db1
Should you use any of the data-formatting options to dump table data, you will need to specify the same format when you reload data files later, to ensure proper interpretation of the file contents.
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-mysqldump-delimited-text.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.