]> git.phdru.name Git - sqlconvert.git/blob - docs/mysql2sql.rst
Remove publish-docs
[sqlconvert.git] / docs / mysql2sql.rst
1 mysql2sql
2 =========
3
4 This is mysql2sql, a mysql to sql converter. It is primary intended to
5 convert mysqldump (especially with extended INSERT syntax) to standard SQL
6 to load at least to PostgreSQL or SQLite.
7
8 The program removes /\*! directives \*/, unquotes names quoted with
9 backticks, quote non-lowercase names with double quotes, unescapes strings
10 and escapes them to a different quoting style, and splits extended INSERTs
11 into a series of plain INSERTs separated by newlines. Everything else is
12 passed unmodified.
13
14
15 .. highlight:: none
16
17 Command line
18 ------------
19
20 mysql2sql
21 ~~~~~~~~~
22
23 Usage::
24
25     mysql2sql [-e encoding] [-E output_encoding] [-m/-p/-s] [infile] [[-o] outfile]
26
27 Options::
28
29     -e ENCODING, --encoding ENCODING
30                            input/output encoding, default is utf-8
31     -E OUTPUT_ENCODING, --output-encoding OUTPUT_ENCODING
32                            separate output encoding, default is the same as
33                            `-e` except for console; for console output charset
34                            from the current locale is used
35     -m, --mysql            MySQL/MariaDB quoting style
36     -p, --pg, --postgres   PostgreSQL quoting style
37     -s, --sqlite           Generic SQL/SQLite quoting style (default)
38     -P, --no-pbar          Inhibit progress bar
39     infile                 Input file, stdin if absent or '-'
40     -o, --outfile outfile  Output file, stdout if absent or '-'
41
42 Options `-m/-p/-s` change quoting style. `-m` sets MySQL quoting style;
43 it's added to use the program in the following scenario: convert MySQL
44 dumps with extended INSERTs to SQL with plain INSERTS suitable to be fed
45 back to MySQL. `-p` sets PostgreSQL quoting style; it's like MySQL with
46 additional `E''-style quoting
47 <https://www.postgresql.org/docs/9.1/static/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE>`_.
48 `-s` sets generic SQL/SQLite quoting style; this is the default.
49
50 If stderr is connected to the console the program displays a text mode
51 progress bar. Option `-P/--no-pbar` inhibits it.
52
53 Option `-o` is useful when infile is absent (input is redirected), for
54 example::
55
56     mysql2sql -o outfile.sql < infile.sql
57     cat infile.sql | mysql2sql -o outfile.sql
58
59 But of course it simply can be::
60
61     mysql2sql - outfile.sql < infile.sql
62     cat infile.sql | mysql2sql - outfile.sql