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

NAME

6       mysql - the MariaDB command-line tool
7

SYNOPSIS

9       mysql [options] db_name
10

DESCRIPTION

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

MYSQL OPTIONS

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

MYSQL COMMANDS

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

MYSQL SERVER-SIDE HELP

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

EXECUTING SQL STATEMENTS FROM A TEXT FILE

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

MYSQL TIPS

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

NOTES

1209        1. Bug#25946
1210           http://bugs.mysql.com/bug.php?id=25946
1211

SEE ALSO

1213       For more information, please refer to the MariaDB Knowledge Base,
1214       available online at https://mariadb.com/kb/
1215

AUTHOR

1217       MariaDB Foundation (http://www.mariadb.org/).
1218
1219
1220
1221MariaDB 10.5                     27 June 2019                         MYSQL(1)
Impressum