1MARIADB(1)                  MariaDB Database System                 MARIADB(1)
2
3
4

NAME

6       mariadb - the MariaDB command-line tool (mysql is now a symlink to
7       mariadb)
8

SYNOPSIS

10       mysql [options] db_name
11

DESCRIPTION

13       mysql is a simple SQL shell (with GNU readline capabilities). It
14       supports interactive and non-interactive use. When used interactively,
15       query results are presented in an ASCII-table format. When used
16       non-interactively (for example, as a filter), the result is presented
17       in tab-separated format. The output format can be changed using command
18       options.
19
20       If you have problems due to insufficient memory for large result sets,
21       use the --quick option. This forces mysql to retrieve results from the
22       server a row at a time rather than retrieving the entire result set and
23       buffering it in memory before displaying it. This is done by returning
24       the result set using the mysql_use_result() C API function in the
25       client/server library rather than mysql_store_result().
26
27       Using mysql is very easy. Invoke it from the prompt of your command
28       interpreter as follows:
29
30           shell> mysql db_name
31
32       Or:
33
34           shell> mysql --user=user_name --password=your_password db_name
35
36       Then type an SQL statement, end it with “;”, \g, or \G and press Enter.
37
38       Typing Control-C causes mysql to attempt to kill the current statement.
39       If this cannot be done, or Control-C is typed again before the
40       statement is killed, mysql exits.
41
42       You can execute SQL statements in a script file (batch file) like this:
43
44           shell> mysql db_name < script.sql > output.tab
45

MYSQL OPTIONS

47       mysql supports the following options, which can be specified on the
48       command line or in the [mysql], [client], [client-server] or [client-
49       mariadb] option file groups.  mysql also supports the options for
50       processing option files.
51
52--help, -?, -I
53
54           Display a help message and exit.
55
56--abort-source-on-error
57
58           Abort 'source filename' operations in case of errors.
59
60--auto-rehash
61
62           Enable automatic rehashing. This option is on by default, which
63           enables database, table, and column name completion. Use
64           --disable-auto-rehash, --no-auto-rehash,  or --skip-auto-rehash to
65           disable rehashing. That causes mysql to start faster, but you must
66           issue the rehash command if you want to use name completion.
67
68           To complete a name, enter the first part and press Tab. If the name
69           is unambiguous, mysql completes it. Otherwise, you can press Tab
70           again to see the possible names that begin with what you have typed
71           so far. Completion does not occur if there is no default database.
72
73--auto-vertical-output
74
75           Automatically switch to vertical output mode if the result is wider
76           than the terminal width.
77
78--batch, -B
79
80           Print results using tab as the column separator, with each row on a
81           new line. With this option, mysql does not use the history file.
82
83           Batch mode results in nontabular output format and escaping of
84           special characters. Escaping may be disabled by using raw mode; see
85           the description for the --raw option.
86
87--binary-mode
88
89           Binary mode allows certain character sequences to be processed as
90           data that would otherwise be treated with a special meaning by the
91           parser.  Specifically, this switch turns off parsing of all client
92           commands except \C and DELIMITER in non-interactive mode (i.e.,
93           when binary mode is combined with either 1) piped input, 2) the
94           --batch mysql option, or 3) the 'source' command). Also, in binary
95           mode, occurrences of '\r\n' and ASCII '\0' are preserved within
96           strings, whereas by default, '\r\n' is translated to '\n' and '\0'
97           is disallowed in user input.
98
99--character-sets-dir=path
100
101           The directory where character sets are installed.
102
103--column-names
104
105           Write column names in results.
106
107--column-type-info, -m
108
109           Display result set metadata.
110
111--comments, -c
112
113           Whether to preserve comments in statements sent to the server. The
114           default is --skip-comments (discard comments), enable with
115           --comments (preserve comments).
116
117--compress, -C
118
119           Compress all information sent between the client and the server if
120           both support compression.
121
122--connect-timeout=seconds
123
124           Set the number of seconds before connection timeout. (Default value
125           is 0.)
126
127--database=db_name, -D db_name
128
129           The database to use.
130
131--debug[=debug_options], -# [debug_options]
132
133           Write a debugging log. A typical debug_options string is
134           ´d:t:o,file_name´. The default is ´d:t:o,/tmp/mysql.trace´.
135
136--debug-check
137
138           Print some debugging information when the program exits.
139
140--debug-info, -T
141
142           Prints debugging information and memory and CPU usage statistics
143           when the program exits.
144
145--default-auth=name
146
147           Default authentication client-side plugin to use.
148
149--default-character-set=charset_name
150
151           Use charset_name as the default character set for the client and
152           connection.
153
154           A common issue that can occur when the operating system uses utf8
155           or another multi-byte character set is that output from the mysql
156           client is formatted incorrectly, due to the fact that the MariaDB
157           client uses the latin1 character set by default. You can usually
158           fix such issues by using this option to force the client to use the
159           system character set instead.
160
161--defaults-extra-file=filename
162
163           Set filename as the file to read default options from after the
164           global defaults files has been read.  Must be given as first
165           option.
166
167--defaults-file=filename
168
169           Set filename as the file to read default options from, override
170           global defaults files. Must be given as first option.
171
172--defaults-group-suffix=suffix
173
174           In addition to the groups named on the command line, read groups
175           that have the given suffix.
176
177--delimiter=str
178
179           Set the statement delimiter. The default is the semicolon character
180           (“;”).
181
182--disable-named-commands
183
184           Disable named commands. Use the \* form only, or use named commands
185           only at the beginning of a line ending with a semicolon (“;”).
186           mysql starts with this option enabled by default. However, even
187           with this option, long-format commands still work from the first
188           line. See the section called “MYSQL COMMANDS”.
189
190--enable-cleartext-plugin
191
192           Obsolete option. Exists only for MySQL compatibility.
193
194--execute=statement, -e statement
195
196           Execute the statement and quit. Disables --force and history file.
197           The default output format is like that produced with --batch.
198
199--force, -f
200
201           Continue even if an SQL error occurs. Sets --abort-source-on-error
202           to 0.
203
204--host=host_name, -h host_name
205
206           Connect to the MariaDB server on the given host.
207
208--html, -H
209
210           Produce HTML output.
211
212--ignore-spaces, -i
213
214           Ignore spaces after function names. Allows one to have spaces
215           (including tab characters and new line characters) between function
216           name and '('. The drawback is that this causes built in functions
217           to become reserved words.
218
219--init-command=str
220
221           SQL Command to execute when connecting to the MariaDB server. Will
222           automatically be re-executed when reconnecting.
223
224--line-numbers
225
226           Write line numbers for errors. Disable this with
227           --skip-line-numbers.
228
229--local-infile[={0|1}]
230
231           Enable or disable LOCAL capability for LOAD DATA INFILE. With no
232           value, the option enables LOCAL. The option may be given as
233           --local-infile=0 or --local-infile=1 to explicitly disable or
234           enable LOCAL. Enabling LOCAL has no effect if the server does not
235           also support it.
236
237--max-allowed-packet=num
238
239           Set the maximum packet length to send to or receive from the
240           server. (Default value is 16MB, largest 1GB.)
241
242--max-join-size=num
243
244           Set the automatic limit for rows in a join when using
245           --safe-updates. (Default value is 1,000,000.)
246
247--named-commands, -G
248
249           Enable named mysql commands. Long-format commands are allowed, not
250           just short-format commands. For example, quit and \q both are
251           recognized. Use --skip-named-commands to disable named commands.
252           See the section called “MYSQL COMMANDS”. Disabled by default.
253
254       ••   --net-buffer-length=size
255
256           Set the buffer size for TCP/IP and socket communication. (Default
257           value is 16KB.)
258
259--no-auto-rehash, -A
260
261           This has the same effect as --skip-auto-rehash. See the description
262           for --auto-rehash.
263
264--no-beep, -b
265
266           Do not beep when errors occur.
267
268--no-defaults
269
270           Do not read default options from any option file. This must be
271           given as the first argument.
272
273--one-database, -o
274
275           Ignore statements except those those that occur while the default
276           database is the one named on the command line. This filtering is
277           limited, and based only on USE statements. This is useful for
278           skipping updates to other databases in the binary log.
279
280--pager[=command]
281
282           Use the given command for paging query output. If the command is
283           omitted, the default pager is the value of your PAGER environment
284           variable. Valid pagers are less, more, cat [> filename], and so
285           forth. This option works only on Unix and only in interactive mode.
286           To disable paging, use --skip-pager.  the section called “MYSQL
287           COMMANDS”, discusses output paging further.
288
289--password[=password], -p[password]
290
291           The password to use when connecting to the server. If you use the
292           short option form (-p), you cannot have a space between the option
293           and the password. If you omit the password value following the
294           --password or -p option on the command line, mysql prompts for one.
295
296           Specifying a password on the command line should be considered
297           insecure. You can use an option file to avoid giving the password
298           on the command line.
299
300--pipe, -W
301
302           On Windows, connect to the server via a named pipe. This option
303           applies only if the server supports named-pipe connections.
304
305--plugin-dir=dir_name
306
307           Directory for client-side plugins.
308
309--port=port_num, -P port_num
310
311           The TCP/IP port number to use for the connection or 0 for default
312           to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services,
313           built-in default (3306).
314
315--print-defaults
316
317           Print the program argument list and exit. This must be given as the
318           first argument.
319
320--progress-reports
321
322           Get progress reports for long running commands (such as ALTER
323           TABLE). (Defaults to on; use --skip-progress-reports to disable.)
324
325--prompt=format_str
326
327           Set the prompt to the specified format. The special sequences that
328           the prompt can contain are described in the section called “MYSQL
329           COMMANDS”.
330
331--protocol={TCP|SOCKET|PIPE|MEMORY}
332
333           The connection protocol to use for connecting to the server. It is
334           useful when the other connection parameters normally would cause a
335           protocol to be used other than the one you want.
336
337--quick, -q
338
339           Do not cache each query result, print each row as it is received.
340           This may slow down the server if the output is suspended. With this
341           option, mysql does not use the history file.
342
343--raw, -r
344
345           For tabular output, the “boxing” around columns enables one column
346           value to be distinguished from another. For nontabular output (such
347           as is produced in batch mode or when the --batch or --silent option
348           is given), special characters are escaped in the output so they can
349           be identified easily. Newline, tab, NUL, and backslash are written
350           as \n, \t, \0, and \\. The --raw option disables this character
351           escaping.
352
353           The following example demonstrates tabular versus nontabular output
354           and the use of raw mode to disable escaping:
355
356               % mysql
357               mysql> SELECT CHAR(92);
358               +----------+
359               | CHAR(92) |
360               +----------+
361               | \        |
362               +----------+
363               % mysql -s
364               mysql> SELECT CHAR(92);
365               CHAR(92)
366               \\
367               % mysql -s -r
368               mysql> SELECT CHAR(92);
369               CHAR(92)
370               \
371
372--reconnect
373
374           If the connection to the server is lost, automatically try to
375           reconnect. A single reconnect attempt is made each time the
376           connection is lost. Enabled by default, to disable use
377           --skip-reconnect or --disable-reconnect.
378
379--safe-updates, --i-am-a-dummy, -U
380
381           Allow only those UPDATE and DELETE statements that specify which
382           rows to modify by using key values. If you have set this option in
383           an option file, you can override it by using --safe-updates on the
384           command line. See the section called “MYSQL TIPS”, for more
385           information about this option.
386
387--secure-auth
388
389           Do not send passwords to the server in old (pre-4.1.1) format. This
390           prevents connections except for servers that use the newer password
391           format.
392
393--select-limit=limit
394
395           Set automatic limit for SELECT when using --safe-updates. (Default
396           value is 1,000.)
397
398--server-arg=name
399
400           Send name as a parameter to the embedded server.
401
402--show-warnings
403
404           Cause warnings to be shown after each statement if there are any.
405           This option applies to interactive and batch mode.
406
407--sigint-ignore
408
409           Ignore SIGINT signals (typically the result of typing Control-C).
410
411--silent, -s
412
413           Silent mode. Produce less output. This option can be given multiple
414           times to produce less and less output.
415
416           This option results in nontabular output format and escaping of
417           special characters. Escaping may be disabled by using raw mode; see
418           the description for the --raw option.
419
420--skip-auto-rehash
421
422           Disable automatic rehashing. Synonym for --disable-auto-rehash.
423
424--skip-column-names, -N
425
426           Do not write column names in results.
427
428--skip-line-numbers, -L
429
430           Do not write line numbers for errors. Useful when you want to
431           compare result files that include error messages.
432
433--socket=path, -S path
434
435           For connections to localhost, the Unix socket file to use, or, on
436           Windows, the name of the named pipe to use.
437
438--ssl
439
440           Enable SSL for connection (automatically enabled with other flags).
441           Disable with --skip-ssl.
442
443--ssl-ca=name
444
445           CA file in PEM format (check OpenSSL docs, implies --ssl).
446
447--ssl-capath=name
448
449           CA directory (check OpenSSL docs, implies --ssl).
450
451--ssl-cert=name
452
453           X509 cert in PEM format (check OpenSSL docs, implies --ssl).
454
455--ssl-cipher=name
456
457           SSL cipher to use (check OpenSSL docs, implies --ssl).
458
459--ssl-key=name
460
461           X509 key in PEM format (check OpenSSL docs, implies --ssl).
462
463--ssl-crl=name
464
465           Certificate revocation list (check OpenSSL docs, implies --ssl).
466
467--ssl-crlpath=name
468
469           Certificate revocation list path (check OpenSSL docs, implies
470           --ssl).
471
472--ssl-verify-server-cert
473
474           Verify server's "Common Name" in its cert against hostname used
475           when connecting. This option is disabled by default.
476
477--table, -t
478
479           Display output in table format. This is the default for interactive
480           use, but can be used to produce table output in batch mode.
481
482--tee=file_name
483
484           Append a copy of output to the given file. This option works only
485           in interactive mode.  the section called “MYSQL COMMANDS”,
486           discusses tee files further.
487
488--unbuffered, -n
489
490           Flush the buffer after each query.
491
492--user=user_name, -u user_name
493
494           The MariaDB user name to use when connecting to the server.
495
496--verbose, -v
497
498           Verbose mode. Produce more output about what the program does. This
499           option can be given multiple times to produce more and more output.
500           (For example, -v -v -v produces table output format even in batch
501           mode.)
502
503--version, -V
504
505           Display version information and exit.
506
507--vertical, -E
508
509           Print query output rows vertically (one line per column value).
510           Without this option, you can specify vertical output for individual
511           statements by terminating them with \G.
512
513--wait, -w
514
515           If the connection cannot be established, wait and retry instead of
516           aborting.
517
518--xml, -X
519
520           Produce XML output.  The output when --xml is used with mysql
521           matches that of mysqldump --xml. See mysqldump(1) for details.
522
523           The XML output also uses an XML namespace, as shown here:
524
525               shell> mysql --xml -uroot -e "SHOW VARIABLES LIKE ´version%´"
526               <?xml version="1.0"?>
527               <resultset statement="SHOW VARIABLES LIKE ´version%´" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
528               <row>
529               <field name="Variable_name">version</field>
530               <field name="Value">5.0.40-debug</field>
531               </row>
532               <row>
533               <field name="Variable_name">version_comment</field>
534               <field name="Value">Source distribution</field>
535               </row>
536               <row>
537               <field name="Variable_name">version_compile_machine</field>
538               <field name="Value">i686</field>
539               </row>
540               <row>
541               <field name="Variable_name">version_compile_os</field>
542               <field name="Value">suse-linux-gnu</field>
543               </row>
544               </resultset>
545
546           You can also set the following variables by using --var_name=value.
547
548           •   connect_timeout
549
550               The number of seconds before connection timeout. (Default value
551               is 0.)
552
553           •   max_allowed_packet
554
555               The maximum packet length to send to or receive from the
556               server. (Default value is 16MB.)
557
558           •   max_join_size
559
560               The automatic limit for rows in a join when using
561               --safe-updates. (Default value is 1,000,000.)
562
563           •   net_buffer_length
564
565               The buffer size for TCP/IP and socket communication. (Default
566               value is 16KB.)
567
568           •   select_limit
569
570               The automatic limit for SELECT statements when using
571               --safe-updates. (Default value is 1,000.)
572
573           On Unix, the mysql client writes a record of executed statements to
574           a history file. By default, this file is named .mysql_history and
575           is created in your home directory. To specify a different file, set
576           the value of the MYSQL_HISTFILE environment variable.
577
578           The .mysql_history should be protected with a restrictive access
579           mode because sensitive information might be written to it, such as
580           the text of SQL statements that contain passwords.
581
582           If you do not want to maintain a history file, first remove
583           .mysql_history if it exists, and then use either of the following
584           techniques:
585
586           •   Set the MYSQL_HISTFILE variable to /dev/null. To cause this
587               setting to take effect each time you log in, put the setting in
588               one of your shell´s startup files.
589
590           •   Create .mysql_history as a symbolic link to /dev/null:
591
592                   shell> ln -s /dev/null $HOME/.mysql_history
593
594               You need do this only once.
595

MYSQL COMMANDS

597       mysql sends each SQL statement that you issue to the server to be
598       executed. There is also a set of commands that mysql itself interprets.
599       For a list of these commands, type help or \h at the mysql> prompt:
600
601           mysql> help
602           List of all MySQL commands:
603           Note that all text commands must be first on line and end with ´;´
604           ?         (\?) Synonym for `help´.
605           clear     (\c) Clear command.
606           connect   (\r) Reconnect to the server. Optional arguments are db and host.
607           delimiter (\d) Set statement delimiter.
608           edit      (\e) Edit command with $EDITOR.
609           ego       (\G) Send command to mysql server, display result vertically.
610           exit      (\q) Exit mysql. Same as quit.
611           go        (\g) Send command to mysql server.
612           help      (\h) Display this help.
613           nopager   (\n) Disable pager, print to stdout.
614           notee     (\t) Don´t write into outfile.
615           pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
616           print     (\p) Print current command.
617           prompt    (\R) Change your mysql prompt.
618           quit      (\q) Quit mysql.
619           rehash    (\#) Rebuild completion hash.
620           source    (\.) Execute an SQL script file. Takes a file name as an argument.
621           status    (\s) Get status information from the server.
622           system    (\!) Execute a system shell command.
623           tee       (\T) Set outfile [to_outfile]. Append everything into given
624                          outfile.
625           use       (\u) Use another database. Takes database name as argument.
626           charset   (\C) Switch to another charset. Might be needed for processing
627                          binlog with multi-byte charsets.
628           warnings  (\W) Show warnings after every statement.
629           nowarning (\w) Don´t show warnings after every statement.
630           For server side help, type ´help contents´
631
632       Each command has both a long and short form. The long form is not case
633       sensitive; the short form is. The long form can be followed by an
634       optional semicolon terminator, but the short form should not.
635
636       The use of short-form commands within multi-line /* ... */ comments is
637       not supported.
638
639help [arg], \h [arg], \? [arg], ? [arg]
640
641           Display a help message listing the available mysql commands.
642
643           If you provide an argument to the help command, mysql uses it as a
644           search string to access server-side help. For more information, see
645           the section called “MYSQL SERVER-SIDE HELP”.
646
647charset charset_name, \C charset_name
648
649           Change the default character set and issue a SET NAMES statement.
650           This enables the character set to remain synchronized on the client
651           and server if mysql is run with auto-reconnect enabled (which is
652           not recommended), because the specified character set is used for
653           reconnects.
654
655clear, \c
656
657           Clear the current input. Use this if you change your mind about
658           executing the statement that you are entering.
659
660connect [db_name host_name]], \r [db_name host_name]]
661
662           Reconnect to the server. The optional database name and host name
663           arguments may be given to specify the default database or the host
664           where the server is running. If omitted, the current values are
665           used.
666
667delimiter str, \d str
668
669           Change the string that mysql interprets as the separator between
670           SQL statements. The default is the semicolon character (“;”).
671
672           The delimiter can be specified as an unquoted or quoted argument.
673           Quoting can be done with either single quote (´) or douple quote
674           (") characters. To include a quote within a quoted string, either
675           quote the string with the other quote character or escape the quote
676           with a backslash (“\”) character. Backslash should be avoided
677           outside of quoted strings because it is the escape character for
678           MariaDB. For an unquoted argument, the delmiter is read up to the
679           first space or end of line. For a quoted argument, the delimiter is
680           read up to the matching quote on the line.
681
682           When the delimiter recognized by mysql is set to something other
683           than the default of “;”, instances of that character are sent to
684           the server without interpretation. However, the server itself still
685           interprets “;” as a statement delimiter and processes statements
686           accordingly. This behavior on the server side comes into play for
687           multiple-statement execution, and for parsing the body of stored
688           procedures and functions, triggers, and events.
689
690edit, \e
691
692           Edit the current input statement.  mysql checks the values of the
693           EDITOR and VISUAL environment variables to determine which editor
694           to use. The default editor is vi if neither variable is set.
695
696           The edit command works only in Unix.
697
698ego, \G
699
700           Send the current statement to the server to be executed and display
701           the result using vertical format.
702
703exit, \q
704
705           Exit mysql.
706
707go, \g
708
709           Send the current statement to the server to be executed.
710
711nopager, \n
712
713           Disable output paging. See the description for pager.
714
715           The nopager command works only in Unix.
716
717notee, \t
718
719           Disable output copying to the tee file. See the description for
720           tee.
721
722nowarning, \w
723
724           Enable display of warnings after each statement.
725
726pager [command], \P [command]
727
728           Enable output paging. By using the --pager option when you invoke
729           mysql, it is possible to browse or search query results in
730           interactive mode with Unix programs such as less, more, or any
731           other similar program. If you specify no value for the option,
732           mysql checks the value of the PAGER environment variable and sets
733           the pager to that. Pager functionality works only in interactive
734           mode.
735
736           Output paging can be enabled interactively with the pager command
737           and disabled with nopager. The command takes an optional argument;
738           if given, the paging program is set to that. With no argument, the
739           pager is set to the pager that was set on the command line, or
740           stdout if no pager was specified.
741
742           Output paging works only in Unix because it uses the popen()
743           function, which does not exist on Windows. For Windows, the tee
744           option can be used instead to save query output, although it is not
745           as convenient as pager for browsing output in some situations.
746
747print, \p
748
749           Print the current input statement without executing it.
750
751prompt [str], \R [str]
752
753           Reconfigure the mysql prompt to the given string. The special
754           character sequences that can be used in the prompt are described
755           later in this section.
756
757           If you specify the prompt command with no argument, mysql resets
758           the prompt to the default of mysql>.
759
760quit, \q
761
762           Exit mysql.
763
764rehash, \#
765
766           Rebuild the completion hash that enables database, table, and
767           column name completion while you are entering statements. (See the
768           description for the --auto-rehash option.)
769
770source file_name, \. file_name
771
772           Read the named file and executes the statements contained therein.
773           On Windows, you can specify path name separators as / or \\.
774
775status, \s
776
777           Provide status information about the connection and the server you
778           are using. If you are running in --safe-updates mode, status also
779           prints the values for the mysql variables that affect your queries.
780
781system command, \! command
782
783           Execute the given command using your default command interpreter.
784
785           The system command works only in Unix.
786
787tee [file_name], \T [file_name]
788
789           By using the --tee option when you invoke mysql, you can log
790           statements and their output. All the data displayed on the screen
791           is appended into a given file. This can be very useful for
792           debugging purposes also.  mysql flushes results to the file after
793           each statement, just before it prints its next prompt. Tee
794           functionality works only in interactive mode.
795
796           You can enable this feature interactively with the tee command.
797           Without a parameter, the previous file is used. The tee file can be
798           disabled with the notee command. Executing tee again re-enables
799           logging.
800
801use db_name, \u db_name
802
803           Use db_name as the default database.
804
805warnings, \W
806
807           Enable display of warnings after each statement (if there are any).
808
809       Here are a few tips about the pager command:
810
811       •   You can use it to write to a file and the results go only to the
812           file:
813
814               mysql> pager cat > /tmp/log.txt
815
816           You can also pass any options for the program that you want to use
817           as your pager:
818
819               mysql> pager less -n -i -S
820
821       •   In the preceding example, note the -S option. You may find it very
822           useful for browsing wide query results. Sometimes a very wide
823           result set is difficult to read on the screen. The -S option to
824           less can make the result set much more readable because you can
825           scroll it horizontally using the left-arrow and right-arrow keys.
826           You can also use -S interactively within less to switch the
827           horizontal-browse mode on and off. For more information, read the
828           less manual page:
829
830               shell> man less
831
832       •   The -F and -X options may be used with less to cause it to exit if
833           output fits on one screen, which is convenient when no scrolling is
834           necessary:
835
836               mysql> pager less -n -i -S -F -X
837
838       •   You can specify very complex pager commands for handling query
839           output:
840
841               mysql> pager cat | tee /dr1/tmp/res.txt \
842                         | tee /dr2/tmp/res2.txt | less -n -i -S
843
844           In this example, the command would send query results to two files
845           in two different directories on two different file systems mounted
846           on /dr1 and /dr2, yet still display the results onscreen via less.
847
848       You can also combine the tee and pager functions. Have a tee file
849       enabled and pager set to less, and you are able to browse the results
850       using the less program and still have everything appended into a file
851       the same time. The difference between the Unix tee used with the pager
852       command and the mysql built-in tee command is that the built-in tee
853       works even if you do not have the Unix tee available. The built-in tee
854       also logs everything that is printed on the screen, whereas the Unix
855       tee used with pager does not log quite that much. Additionally, tee
856       file logging can be turned on and off interactively from within mysql.
857       This is useful when you want to log some queries to a file, but not
858       others.
859
860       The prompt command reconfigures the default mysql> prompt. The string
861       for defining the prompt can contain the following special sequences.
862
863       ┌───────┬────────────────────────────┐
864Option Description                
865       ├───────┼────────────────────────────┤
866       │\c     │ A counter that increments  │
867       │       │ for each statement you     │
868       │       │ issue                      │
869       ├───────┼────────────────────────────┤
870       │\D     │ The full current date      │
871       ├───────┼────────────────────────────┤
872       │\d     │ The default database       │
873       ├───────┼────────────────────────────┤
874       │\h     │ The server host            │
875       ├───────┼────────────────────────────┤
876       │\l     │ The current delimiter (new │
877       │       │ in 5.1.12)                 │
878       ├───────┼────────────────────────────┤
879       │\m     │ Minutes of the current     │
880       │       │ time                       │
881       ├───────┼────────────────────────────┤
882       │\n     │ A newline character        │
883       ├───────┼────────────────────────────┤
884       │\O     │ The current month in       │
885       │       │ three-letter format (Jan,  │
886       │       │ Feb, ...)                  │
887       ├───────┼────────────────────────────┤
888       │\o     │ The current month in       │
889       │       │ numeric format             │
890       ├───────┼────────────────────────────┤
891       │\P     │ am/pm                      │
892       ├───────┼────────────────────────────┤
893       │\p     │ The current TCP/IP port or │
894       │       │ socket file                │
895       ├───────┼────────────────────────────┤
896       │\R     │ The current time, in       │
897       │       │ 24-hour military time      │
898       │       │ (0–23)                     │
899       ├───────┼────────────────────────────┤
900       │\r     │ The current time, standard │
901       │       │ 12-hour time (1–12)        │
902       ├───────┼────────────────────────────┤
903       │\S     │ Semicolon                  │
904       ├───────┼────────────────────────────┤
905       │\s     │ Seconds of the current     │
906       │       │ time                       │
907       ├───────┼────────────────────────────┤
908       │\t     │ A tab character            │
909       ├───────┼────────────────────────────┤
910       │\U     │                            │
911       │       │        Your full           │
912       │       │        user_name@host_name
913       │       │        account name        │
914       ├───────┼────────────────────────────┤
915       │\u     │ Your user name             │
916       ├───────┼────────────────────────────┤
917       │\v     │ The server version         │
918       ├───────┼────────────────────────────┤
919       │\w     │ The current day of the     │
920       │       │ week in three-letter       │
921       │       │ format (Mon, Tue, ...)     │
922       ├───────┼────────────────────────────┤
923       │\Y     │ The current year, four     │
924       │       │ digits                     │
925       ├───────┼────────────────────────────┤
926       │\y     │ The current year, two      │
927       │       │ digits                     │
928       ├───────┼────────────────────────────┤
929       │\_     │ A space                    │
930       ├───────┼────────────────────────────┤
931       │\      │ A space (a space follows   │
932       │       │ the backslash)             │
933       ├───────┼────────────────────────────┤
934       │\´     │ Single quote               │
935       ├───────┼────────────────────────────┤
936       │\"     │ Double quote               │
937       ├───────┼────────────────────────────┤
938       │\\     │ A literal “\” backslash    │
939       │       │ character                  │
940       ├───────┼────────────────────────────┤
941       │\x     │                            │
942       │       │        x, for any “x” not  │
943       │       │        listed above        │
944       └───────┴────────────────────────────┘
945
946       You can set the prompt in several ways:
947
948Use an environment variable.  You can set the MYSQL_PS1 environment
949           variable to a prompt string. For example:
950
951               shell> export MYSQL_PS1="(\u@\h) [\d]> "
952
953Use a command-line option.  You can set the --prompt option on the
954           command line to mysql. For example:
955
956               shell> mysql --prompt="(\u@\h) [\d]> "
957               (user@host) [database]>
958
959Use an option file.  You can set the prompt option in the [mysql]
960           group of any MariaDB option file, such as /etc/my.cnf or the
961           .my.cnf file in your home directory. For example:
962
963               [mysql]
964               prompt=(\\u@\\h) [\\d]>\\_
965
966           In this example, note that the backslashes are doubled. If you set
967           the prompt using the prompt option in an option file, it is
968           advisable to double the backslashes when using the special prompt
969           options. There is some overlap in the set of allowable prompt
970           options and the set of special escape sequences that are recognized
971           in option files. The overlap may cause you problems if you use
972           single backslashes. For example, \s is interpreted as a space
973           rather than as the current seconds value. The following example
974           shows how to define a prompt within an option file to include the
975           current time in HH:MM:SS> format:
976
977               [mysql]
978               prompt="\\r:\\m:\\s> "
979
980Set the prompt interactively.  You can change your prompt
981           interactively by using the prompt (or \R) command. For example:
982
983               mysql> prompt (\u@\h) [\d]>\_
984               PROMPT set to ´(\u@\h) [\d]>\_´
985               (user@host) [database]>
986               (user@host) [database]> prompt
987               Returning to default PROMPT of mysql>
988               mysql>
989

MYSQL SERVER-SIDE HELP

991           mysql> help search_string
992
993       If you provide an argument to the help command, mysql uses it as a
994       search string to access server-side help. The proper operation of this
995       command requires that the help tables in the mysql database be
996       initialized with help topic information.
997
998       If there is no match for the search string, the search fails:
999
1000           mysql> help me
1001           Nothing found
1002           Please try to run ´help contents´ for a list of all accessible topics
1003
1004       Use help contents to see a list of the help categories:
1005
1006           mysql> help contents
1007           You asked for help about help category: "Contents"
1008           For more information, type ´help <item>´, where <item> is one of the
1009           following categories:
1010              Account Management
1011              Administration
1012              Data Definition
1013              Data Manipulation
1014              Data Types
1015              Functions
1016              Functions and Modifiers for Use with GROUP BY
1017              Geographic Features
1018              Language Structure
1019              Plugins
1020              Storage Engines
1021              Stored Routines
1022              Table Maintenance
1023              Transactions
1024              Triggers
1025
1026       If the search string matches multiple items, mysql shows a list of
1027       matching topics:
1028
1029           mysql> help logs
1030           Many help items for your request exist.
1031           To make a more specific request, please type ´help <item>´,
1032           where <item> is one of the following topics:
1033              SHOW
1034              SHOW BINARY LOGS
1035              SHOW ENGINE
1036              SHOW LOGS
1037
1038       Use a topic as the search string to see the help entry for that topic:
1039
1040           mysql> help show binary logs
1041           Name: ´SHOW BINARY LOGS´
1042           Description:
1043           Syntax:
1044           SHOW BINARY LOGS
1045           SHOW MASTER LOGS
1046           Lists the binary log files on the server. This statement is used as
1047           part of the procedure described in [purge-binary-logs], that shows how
1048           to determine which logs can be purged.
1049           mysql> SHOW BINARY LOGS;
1050           +---------------+-----------+
1051           | Log_name      | File_size |
1052           +---------------+-----------+
1053           | binlog.000015 |    724935 |
1054           | binlog.000016 |    733481 |
1055           +---------------+-----------+
1056

EXECUTING SQL STATEMENTS FROM A TEXT FILE

1058       The mysql client typically is used interactively, like this:
1059
1060           shell> mysql db_name
1061
1062       However, it is also possible to put your SQL statements in a file and
1063       then tell mysql to read its input from that file. To do so, create a
1064       text file text_file that contains the statements you wish to execute.
1065       Then invoke mysql as shown here:
1066
1067           shell> mysql db_name < text_file
1068
1069       If you place a USE db_name statement as the first statement in the
1070       file, it is unnecessary to specify the database name on the command
1071       line:
1072
1073           shell> mysql < text_file
1074
1075       If you are already running mysql, you can execute an SQL script file
1076       using the source command or \.  command:
1077
1078           mysql> source file_name
1079           mysql> \. file_name
1080
1081       Sometimes you may want your script to display progress information to
1082       the user. For this you can insert statements like this:
1083
1084           SELECT ´<info_to_display>´ AS ´ ´;
1085
1086       The statement shown outputs <info_to_display>.
1087
1088       You can also invoke mysql with the --verbose option, which causes each
1089       statement to be displayed before the result that it produces.
1090
1091       mysql ignores Unicode byte order mark (BOM) characters at the beginning
1092       of input files. Presence of a BOM does not cause mysql to change its
1093       default character set. To do that, invoke mysql with an option such as
1094       --default-character-set=utf8.
1095

MYSQL TIPS

1097       This section describes some techniques that can help you use mysql more
1098       effectively.
1099
1100   Displaying Query Results Vertically
1101       Some query results are much more readable when displayed vertically,
1102       instead of in the usual horizontal table format. Queries can be
1103       displayed vertically by terminating the query with \G instead of a
1104       semicolon. For example, longer text values that include newlines often
1105       are much easier to read with vertical output:
1106
1107           mysql> SELECT * FROM mails WHERE LENGTH(txt) < 300 LIMIT 300,1\G
1108           *************************** 1. row ***************************
1109             msg_nro: 3068
1110                date: 2000-03-01 23:29:50
1111           time_zone: +0200
1112           mail_from: Monty
1113               reply: monty@no.spam.com
1114             mail_to: "Thimble Smith" <tim@no.spam.com>
1115                 sbj: UTF-8
1116                 txt: >>>>> "Thimble" == Thimble Smith writes:
1117           Thimble> Hi.  I think this is a good idea.  Is anyone familiar
1118           Thimble> with UTF-8 or Unicode? Otherwise, I´ll put this on my
1119           Thimble> TODO list and see what happens.
1120           Yes, please do that.
1121           Regards,
1122           Monty
1123                file: inbox-jani-1
1124                hash: 190402944
1125           1 row in set (0.09 sec)
1126
1127   Using the --safe-updates Option
1128       For beginners, a useful startup option is --safe-updates (or
1129       --i-am-a-dummy, which has the same effect). It is helpful for cases
1130       when you might have issued a DELETE FROM tbl_name statement but
1131       forgotten the WHERE clause. Normally, such a statement deletes all rows
1132       from the table. With --safe-updates, you can delete rows only by
1133       specifying the key values that identify them. This helps prevent
1134       accidents.
1135
1136       When you use the --safe-updates option, mysql issues the following
1137       statement when it connects to the MariaDB server:
1138
1139           SET sql_safe_updates=1, sql_select_limit=1000, sql_max_join_size=1000000;
1140
1141       The SET statement has the following effects:
1142
1143       •   You are not allowed to execute an UPDATE or DELETE statement unless
1144           you specify a key constraint in the WHERE clause or provide a LIMIT
1145           clause (or both). For example:
1146
1147               UPDATE tbl_name SET not_key_column=val WHERE key_column=val;
1148               UPDATE tbl_name SET not_key_column=val LIMIT 1;
1149
1150       •   The server limits all large SELECT results to 1,000 rows unless the
1151           statement includes a LIMIT clause.
1152
1153       •   The server aborts multiple-table SELECT statements that probably
1154           need to examine more than 1,000,000 row combinations.
1155
1156       To specify limits different from 1,000 and 1,000,000, you can override
1157       the defaults by using the --select-limit and --max-join-size options:
1158
1159           shell> mysql --safe-updates --select-limit=500 --max-join-size=10000
1160
1161   Disabling mysql Auto-Reconnect
1162       If the mysql client loses its connection to the server while sending a
1163       statement, it immediately and automatically tries to reconnect once to
1164       the server and send the statement again. However, even if mysql
1165       succeeds in reconnecting, your first connection has ended and all your
1166       previous session objects and settings are lost: temporary tables, the
1167       autocommit mode, and user-defined and session variables. Also, any
1168       current transaction rolls back. This behavior may be dangerous for you,
1169       as in the following example where the server was shut down and
1170       restarted between the first and second statements without you knowing
1171       it:
1172
1173           mysql> SET @a=1;
1174           Query OK, 0 rows affected (0.05 sec)
1175           mysql> INSERT INTO t VALUES(@a);
1176           ERROR 2006: MySQL server has gone away
1177           No connection. Trying to reconnect...
1178           Connection id:    1
1179           Current database: test
1180           Query OK, 1 row affected (1.30 sec)
1181           mysql> SELECT * FROM t;
1182           +------+
1183           | a    |
1184           +------+
1185           | NULL |
1186           +------+
1187           1 row in set (0.05 sec)
1188
1189       The @a user variable has been lost with the connection, and after the
1190       reconnection it is undefined. If it is important to have mysql
1191       terminate with an error if the connection has been lost, you can start
1192       the mysql client with the --skip-reconnect option.
1193
1195       Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc.,
1196       2010-2019 MariaDB Foundation
1197
1198       This documentation is free software; you can redistribute it and/or
1199       modify it only under the terms of the GNU General Public License as
1200       published by the Free Software Foundation; version 2 of the License.
1201
1202       This documentation is distributed in the hope that it will be useful,
1203       but WITHOUT ANY WARRANTY; without even the implied warranty of
1204       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1205       General Public License for more details.
1206
1207       You should have received a copy of the GNU General Public License along
1208       with the program; if not, write to the Free Software Foundation, Inc.,
1209       51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA or see
1210       http://www.gnu.org/licenses/.
1211
1212

NOTES

1214        1. Bug#25946
1215           http://bugs.mysql.com/bug.php?id=25946
1216

SEE ALSO

1218       For more information, please refer to the MariaDB Knowledge Base,
1219       available online at https://mariadb.com/kb/
1220

AUTHOR

1222       MariaDB Foundation (http://www.mariadb.org/).
1223
1224
1225
1226MariaDB 10.5                     27 June 2019                       MARIADB(1)
Impressum