MARIADB(1)
๐ธ MARIADB(1) โ the MariaDB Database System's command-line tool ๐ธ
okay bestie, buckle up, this is the mariadb manual page (it lives in the MariaDB Database System section of your man pages) and it's a whole journey. we're doing this together. ๐ซถ
๐ NAME ๐
mariadb โ the MariaDB command-line tool. and yes, plot twist: mysql is now a symlink to mariadb. iconic behavior honestly.
โจ SYNOPSIS โจ
mariadb [options] db_name
๐ฆ DESCRIPTION ๐ฆ
so mariadb is a simple SQL shell, but make it GNU readline-capable. she does interactive and non-interactive use, she contains multitudes.
- when you use her interactively, query results show up in an ASCII-table format. very demure, very mindful.
- when you use her non-interactively (like, as a filter, slay), the result comes out in tab-separated format.
and guess what โ the output format can be changed with command options. you're not locked in, bestie.
if you're having problems because there isn't enough memory for big result sets, use the --quick option. that forces mariadb to grab results from the server one row at a time instead of pulling the entire result set and buffering it all in memory before showing it. how does it do that? by returning the result set using the mariadb_use_result() C API function in the client/server library instead of mysql_store_result(). no cap.
using mariadb is genuinely so easy. invoke her from your command interpreter's prompt like this:
shell> mariadb db_name
or:
shell> mariadb --user=user_name --password=your_password db_name
then just type an SQL statement, end it with ;, \g, or \G, and hit Enter. periodt.
typing Control-C makes mariadb try to kill the current statement. if that can't be done, or if you type Control-C again before the statement is killed, mariadb exits. ๐
you can also run SQL statements in a script file (batch file) like this:
shell> mariadb db_name < script.sql > output.tab
๐ MARIADB OPTIONS ๐
mariadb supports all these options, and you can specify them on the command line or in the [mariadb], [client], [client-server] or [client-mariadb] option file groups. she also supports the options for processing option files. let's go, one by one, no skipping. ๐
--help,-?,-Iโ show a help message and exit. that's it, that's the whole thing.--abort-source-on-errorโ abortsource filenameoperations if errors happen.--auto-rehashโ turn on automatic rehashing. this one is on by default, and it enables database, table, and column name completion. wanna turn it off? use--disable-auto-rehash,--no-auto-rehash, or--skip-auto-rehash. that makesmariadbstart faster, but then you gotta issue therehashcommand if you want name completion back.
to complete a name, type the first part and press Tab. if the name is unambiguous, mariadb finishes it for you. otherwise, press Tab again to see all the possible names starting with what you've typed so far. heads up: completion does not happen if there's no default database. ๐
--auto-vertical-outputโ automatically switch to vertical output mode when the result is wider than your terminal width. she knows her limits, respectfully.--batch,-Bโ print results using tab as the column separator, one row per new line. with this option,mariadbdoes not use the history file.
batch mode gives you nontabular output format plus escaping of special characters. you can disable that escaping with raw mode โ go read the description for the --raw option.
--binary-modeโ binary mode lets certain character sequences be processed as data that the parser would otherwise treat as having a special meaning. specifically: this switch turns off parsing of all client commands except\CandDELIMITERin non-interactive mode (aka when binary mode is combined with either 1) piped input, 2) the--batchmariadboption, or 3) thesourcecommand). also, in binary mode, occurrences of'\r\n'and ASCII'\0'are preserved inside strings โ whereas by default,'\r\n'gets translated to'\n'and'\0'is disallowed in user input.--character-sets-dir=pathโ the directory where character sets are installed.--column-namesโ write column names in results. names! in your results!--column-type-info,-mโ display result set metadata.--comments,-cโ whether to preserve comments in statements sent to the server. the default is--skip-comments(which discards comments); enable with--comments(which preserves them).--compress,-Cโ compress all info sent between the client and the server, if both of them support compression.--connect-timeout=secondsโ set the number of seconds before the connection times out. (default value is0.)--database=db_name,-D db_nameโ the database to use.--debug[=debug_options],-# [debug_options]โ write a debugging log. a typicaldebug_optionsstring is'd:t:o,file_name'. the default is'd:t:o,/tmp/mysql.trace'.--debug-checkโ print some debugging information when the program exits.--debug-info,-Tโ prints debugging information plus memory and CPU usage statistics when the program exits.--default-auth=nameโ the default authentication client-side plugin to use.--default-character-set=charset_nameโ usecharset_nameas the default character set for the client and the connection.
a common issue, and honestly a classic: when your operating system uses utf8 or another multi-byte character set, output from the mariadb client can be formatted incorrectly, because the MariaDB client uses the latin1 character set by default. usually you can fix this by using this option to force the client to use the system character set instead. ๐
--defaults-extra-file=filenameโ setfilenameas the file to read default options from, after the global defaults files have been read. must be given as the first option.--defaults-file=filenameโ setfilenameas the file to read default options from, and override the global defaults files. must be given as the first option.--defaults-group-suffix=suffixโ in addition to the groups named on the command line, read groups that have the given suffix.--delimiter=strโ set the statement delimiter. the default is the semicolon character (;).--disable-named-commandsโ disable named commands. use the\*form only, or use named commands only at the beginning of a line ending with a semicolon (;).mariadbstarts with this option enabled by default. however, even with this option, long-format commands still work from the first line. see the section called "MARIADB COMMANDS".--enable-cleartext-pluginโ obsolete option. she only exists for MySQL compatibility. a little nostalgic queen. ๐--execute=statement,-e statementโ execute the statement and quit. this disables--forceand the history file. the default output format is like the one you'd get with--batch.--force,-fโ keep going even if an SQL error occurs. sets--abort-source-on-errorto0.--host=host_name,-h host_nameโ connect to the MariaDB server on the given host.--html,-Hโ produce HTML output.--ignore-spaces,-iโ ignore spaces after function names. this lets you have spaces (including tab characters and new line characters) between a function name and'('. the drawback? this causes built-in functions to become reserved words. trade-offs, bestie. ๐ญ--init-command=strโ SQL command to execute when connecting to the MariaDB server. it'll automatically be re-executed whenever you reconnect.--line-numbersโ write line numbers for errors. disable it with--skip-line-numbers.--local-infile[={0|1}]โ enable or disableLOCALcapability forLOAD DATA INFILE. with no value, the option enablesLOCAL. you can also give it as--local-infile=0or--local-infile=1to explicitly disable or enableLOCAL. heads up though: enablingLOCALhas no effect if the server doesn't also support it.--max-allowed-packet=numโ set the maximum packet length to send to or receive from the server. (default value is 16MB, largest is 1GB.)--max-join-size=numโ set the automatic limit for rows in a join when you're using--safe-updates. (default value is1,000,000.)--named-commands,-Gโ enable namedmariadbcommands. long-format commands are allowed, not just short-format ones. for example,quitand\qare both recognized. use--skip-named-commandsto disable named commands. see the section called "MARIADB COMMANDS". disabled by default.--net-buffer-length=sizeโ set the buffer size for TCP/IP and socket communication. (default value is 16KB.)--no-auto-rehash,-Aโ same effect as--skip-auto-rehash. see the description for--auto-rehash.--no-beep,-bโ do not beep when errors occur. silence is golden. ๐--no-defaultsโ do not read default options from any option file. this must be given as the first argument.--one-database,-oโ ignore statements except those that occur while the default database is the one named on the command line. this filtering is limited, and based only onUSEstatements. useful for skipping updates to other databases in the binary log.--pager[=command]โ use the given command for paging query output. if you omit the command, the default pager is the value of yourPAGERenvironment variable. valid pagers areless,more,cat [> filename], and so forth. this option works only on Unix and only in interactive mode. to disable paging, use--skip-pager. the section called "MARIADB COMMANDS" talks about output paging even more.--password[=password],-p[password]โ the password to use when connecting to the server. if you use the short option form (-p), you cannot have a space between the option and the password. if you leave out the password value after the--passwordor-poption on the command line,mariadbprompts you for one.
โ ๏ธ specifying a password on the command line should be considered insecure. you can use an option file to avoid putting the password on the command line. protect yourself, bestie. ๐
--pipe,-Wโ on Windows, connect to the server via a named pipe. this option only applies if the server supports named-pipe connections.--plugin-dir=dir_nameโ directory for client-side plugins.--port=port_num,-P port_numโ the TCP/IP port number to use for the connection, or0for the default. the default is chosen in this order of preference:my.cnf,$MYSQL_TCP_PORT,/etc/services, built-in default (3306). specifying this on the command line without other connection properties forces--protocol=tcp.--print-defaultsโ print the program argument list and exit. this must be given as the first argument.
more of this manual is coming, bestie, don't go anywhere ๐ง
--progress-reportsโ get progress reports for long-running commands (looking at you,ALTER TABLE, you absolute unit of a slowpoke). Defaults to on, so if you want it gone, hit it with--skip-progress-reports. ๐--prompt=format_strโ sets your prompt to whatever format_str you want โจ. All the special little sequences you can sneak in there are listed over in the section called โMARIADB COMMANDSโ โ go peek. ๐--protocol={TCP|SOCKET|PIPE|MEMORY}โ the connection protocol for talking to the server, bestie. It's the move when your other connection params would lowkey pick a protocol that isn't the one you actually wanted. ๐--quick,-qโ do not cache each query result; print each row the second it arrives ๐โ๏ธ. Heads up: this can slow the server down if your output gets suspended. Also, with this optionmariadbdoesn't use the history file. No cap.--raw,-rโ okay so for tabular output, the โboxingโ around columns is what lets you tell one column value from another ๐. But for nontabular output (the batch-mode kind, or whenever you passed--batchor--silent), special characters get escaped so you can actually spot them: newline, tab, NUL and backslash get written as\n,\t,\0, and\\.--rawturns that escaping off. Periodt.
Here's the glow-up, tabular vs nontabular vs raw mode with no escaping:
% mariadb
mariadb> SELECT CHAR(92);
+----------+
| CHAR(92) |
+----------+
| \ |
+----------+
% mariadb -s
mariadb> SELECT CHAR(92);
CHAR(92)
\\
% mariadb -s -r
mariadb> SELECT CHAR(92);
CHAR(92)
\
--reconnectโ if the connection to the server dips, it automatically tries to reconnect ๐ซถ. One single reconnect attempt happens each time the connection is lost. Enabled by default, so to shut it off use--skip-reconnector--disable-reconnect.--safe-updates,--i-am-a-dummy,-Uโ only lets throughUPDATEandDELETEstatements that say which rows they're touching, using key values ๐. If you already set this in an option file, you can override it by throwing--safe-updateson the command line. More tea on this one lives in the section called โMARIADB TIPSโ.--secure-authโ do not send passwords to the server in the old (pre-4.1.1) format ๐ซ. That means no connections except to servers that use the newer password format. It's giving secure.--select-limit=limitโ sets the automatic limit forSELECTwhen you're using--safe-updates. Default value is 1,000. โจ--server-arg=nameโ sends name as a parameter to the embedded server. ๐จ--show-warningsโ makes warnings show up after each statement, if there are any ๐จ. Works in both interactive and batch mode.--sigint-ignoreโ ignoresSIGINTsignals (which is usually just you mashing Control-C ๐ญ).--silent,-sโ silent mode: produce less output ๐คซ. You can pass this one multiple times to get less and less and less output.
This option gives you nontabular output format plus escaping of special characters. Escaping can be turned off with raw mode โ go read the --raw description above, iykyk.
--skip-auto-rehashโ disables automatic rehashing. It's a synonym for--disable-auto-rehash. ๐ซ--skip-column-names,-Nโ don't write column names in your results. Just the data, bestie. ๐--skip-line-numbers,-Lโ don't write line numbers for errors. Chef's kiss when you wanna compare result files that include error messages. ๐--socket=path,-S pathโ for connections to localhost, this is the Unix socket file to use, or, on Windows, the name of the named pipe to use ๐. If you specify it on the command line without any other connection properties, it forces--protocol=socket; on Windows, it forces--protocol=pipe.--sslโ enable SSL for the connection (it gets automatically enabled alongside other flags anyway). Disable it with--skip-ssl๐.--ssl-ca=nameโ CA file in PEM format (check the OpenSSL docs; this implies--ssl). ๐--ssl-capath=nameโ CA directory (check the OpenSSL docs; implies--ssl). ๐--ssl-cert=nameโ X509 cert in PEM format (check the OpenSSL docs; implies--ssl). ๐ซ--ssl-cipher=nameโ the SSL cipher to use (check the OpenSSL docs; implies--ssl). ๐ก--ssl-key=nameโ X509 key in PEM format (check the OpenSSL docs; implies--ssl). ๐๏ธ--ssl-crl=nameโ certificate revocation list (check the OpenSSL docs; implies--ssl). ๐--ssl-crlpath=nameโ certificate revocation list path (check the OpenSSL docs; implies--ssl). ๐๏ธ--ssl-verify-server-certโ verifies the server's "Common Name" in its cert against the hostname used when connecting ๐ต๏ธโ๏ธ. This option is disabled by default.--table,-tโ display output in table format โจ. This is the default for interactive use, but you can also use it to get table output while in batch mode.--tee=file_nameโ append a copy of the output to the given file ๐. Heads up: this option works only in interactive mode. The section called โMARIADB COMMANDSโ discusses tee files further.--unbuffered,-nโ flush the buffer after each query ๐ฟ.--user=user_name,-u user_nameโ the MariaDB user name to use when connecting to the server. ๐ค--verbose,-vโ verbose mode: produce more output about what the program is doing ๐ฃ๏ธ. Pass it multiple times to get more and more output. (Like,-v -v -vgives you table output format even in batch mode. Iconic.)--version,-Vโ display version information and exit. Bye bestie ๐.--vertical,-Eโ print query output rows vertically, one line per column value ๐. Don't want the flag? You can still get vertical output for individual statements by ending them with\G.--wait,-wโ if the connection can't be established, wait and retry instead of just aborting ๐ซถ.--xml,-Xโ produce XML output ๐ท๏ธ. When--xmlis used withmariadb, the output matchesmariadb-dump --xml. Seemariadb-dump(1)for the details.
The XML output also uses an XML namespace, like this:
shell> mariadb --xml -uroot -e "SHOW VARIABLES LIKE 'version%'"
<?xml version="1.0"?>
<resultset statement="SHOW VARIABLES LIKE 'version%'" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="Variable_name">version</field>
<field name="Value">5.0.40-debug</field>
</row>
<row>
<field name="Variable_name">version_comment</field>
<field name="Value">Source distribution</field>
</row>
<row>
<field name="Variable_name">version_compile_machine</field>
<field name="Value">i686</field>
</row>
<row>
<field name="Variable_name">version_compile_os</field>
<field name="Value">suse-linux-gnu</field>
</row>
</resultset>
You can also set the following variables by using --var_name=value. ๐
connect_timeoutโ the number of seconds before connection timeout. (Default value is 0.)max_allowed_packetโ the maximum packet length to send to or receive from the server. (Default value is 16MB.)max_join_sizeโ the automatic limit for rows in a join when using--safe-updates. (Default value is 1,000,000.)net_buffer_lengthโ the buffer size for TCP/IP and socket communication. (Default value is 16KB.)select_limitโ the automatic limit forSELECTstatements when using--safe-updates. (Default value is 1,000.)
Okay so on Unix, the mariadb client writes a record of executed statements to a history file ๐. By default this file is named .mariadb_history and it gets created in your home directory. For backwards compatibility .mariadb_history will be used if present and .mariadb_history is missing. Wanna point it somewhere else? Set the value of the MARIADB_HISTFILE environment variable. And the environment variable MYSQL_HISTFILE will be used if MARIADB_HISTFILE isn't present.
Bestie, protect .mariadb_history with a restrictive access mode. Sensitive information might get written to it, like the text of SQL statements that contain passwords. Do not leave that door open. ๐๐ญ
If you do not want to maintain a history file, first remove .mariadb_history if it exists, and then use either of these techniques:
- Set the
MARIADB_HISTFILEvariable to/dev/null. To cause this setting to take effect each time you log in, put the setting in one of your shell's startup files. - Create
.mariadb_historyas a symbolic link to/dev/null:
shell> ln -s /dev/null $HOME/.mariadb_history
You need do this only once. โจ
๐ MARIADB COMMANDS ๐
mariadb sends each SQL statement that you issue to the server to be executed ๐. But there's also a whole set of commands that mariadb itself interprets โ main character energy, honestly. Wanna see the list? Type help or \h at the mariadb> prompt:
๐
mariadb> help
List of all MariaDB commands:
Note that all text commands must be first on line and end with ';'
? (\?) Synonym for 'help'.
clear (\c) Clear command.
connect (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit (\e) Edit command with $EDITOR.
ego (\G) Send command to mariadb server, display result vertically.
exit (\q) Exit mariadb. Same as quit.
go (\g) Send command to mariadb server.
help (\h) Display this help.
nopager (\n) Disable pager, print to stdout.
notee (\t) Don't write into outfile.
pager (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print (\p) Print current command.
prompt (\R) Change your mariadb prompt.
quit (\q) Quit mariadb.
rehash (\#) Rebuild completion hash.
source (\.) Execute an SQL script file. Takes a file name as an argument.
status (\s) Get status information from the server.
system (\!) Execute a system shell command.
tee (\T) Set outfile [to_outfile]. Append everything into given
outfile.
use (\u) Use another database. Takes database name as argument.
charset (\C) Switch to another charset. Might be needed for processing
binlog with multi-byte charsets.
warnings (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type 'help contents'
okay so that's the whole command menu, bestie ๐ โ every single one of them has a long form and a short form, and here's the tea: the long form is not case sensitive, but the short form is. The long form can be followed by an optional semicolon terminator, but the short form should not be. (Rude of it, honestly, but that's the rules.)
๐จ also important: using short-form commands inside multi-line /* ... */ comments is not supported. Don't do it, she will not parse that for you, no cap.
help [arg],\h [arg],\? [arg],? [arg]โ shows you a help message with all the available mariadb commands listed out ๐
If you actually hand it an argument, mariadb treats that as a search string to go fetch server-side help. More deets in the section called โMARIADB SERVER-SIDE HELPโ.
charset charset_name,\C charset_nameโ changes the default character set and fires off aSET NAMESstatement. โจ
This is the moment where the charset stays synced up between client and server if mariadb is running with auto-reconnect enabled (which โ heads up โ is not recommended, bestie), because that specified character set is what gets used for reconnects.
clear,\cโ wipes the current input clean. Use this when you've typed a whole statement and then had the realisation that you do not, in fact, want to send it ๐connect [db_name host_name]], \r [db_name host_name]]โ reconnects to the server. You can pass the optional database name and host name arguments to pick the default database or the host where the server lives. Leave them out and it just uses the current values. ๐delimiter str,\d strโ changes the string mariadb reads as the separator between SQL statements. The default is the semicolon character (โ;โ).
The delimiter can be given as an unquoted or a quoted argument. Quoting works with either single quote (') or double quote (") characters. To sneak a quote inside a quoted string, either wrap the string in the other quote character, or escape the quote with a backslash (โ\โ). Backslash should be avoided outside of quoted strings because it's the escape character for MariaDB, so likeโฆ don't. For an unquoted argument, the delimiter gets read up to the first space or end of line. For a quoted argument, it's read up to the matching quote on the line.
Now the spicy part: when the delimiter mariadb recognises is set to anything other than the default โ;โ, instances of that character get sent to the server without interpretation. BUT โ the server itself still reads โ;โ as a statement delimiter and processes statements accordingly. This server-side behaviour matters for multiple-statement execution, and for parsing the body of stored procedures and functions, triggers, and events. iykyk ๐ง
edit,\eโ lets you edit the current input statement. mariadb checks the values of theEDITORandVISUALenvironment variables to figure out which editor to use. The default editor isviif neither variable is set.
this one works only in Unix, just so you know ๐
ego,\Gโ sends the current statement off to the server to be executed and displays the result using vertical format. It's giving organised. It's giving readable. Obsessed. โญexit,\qโ exits mariadb. bye bestie ๐ฆgo,\gโ sends the current statement to the server to be executed.nopager,\nโ disables output paging. See the description forpager.
also Unix-only, sorry to the Windows girlies ๐ญ
notee,\tโ disables output copying to the tee file. See the description fortee.nowarning,\wโ enables display of warnings after each statement.pager [command],\P [command]โ enables output paging. By using the--pageroption when you invoke mariadb, you can browse or search query results in interactive mode with Unix programs likeless,more, or literally any other similar program. If you give the option no value, mariadb checks the value of thePAGERenvironment variable and sets the pager to that. Pager functionality works only in interactive mode.
Output paging can be switched on interactively with the pager command and switched off with nopager. The command takes an optional argument; if you give one, the paging program is set to that. With no argument, the pager is set to the pager that was set on the command line, or stdout if no pager was specified.
Output paging works only in Unix because it uses the popen() function, which does not exist on Windows. For Windows, the tee option can be used instead to save query output, although it is not as convenient as pager for browsing output in some situations. ๐ซถ
print,\pโ prints the current input statement without executing it. Peek, don't yeet.prompt [str],\R [str]โ reconfigures the mariadb prompt to whatever string you give it. The special character sequences you can use in the prompt are described later in this section. โจ
If you run the prompt command with no argument at all, mariadb resets the prompt to the default of mariadb>.
quit,\qโ exits mariadb.rehash,\#โ rebuilds the completion hash, the thing that enables database, table, and column name completion while you're typing statements. (See the description for the--auto-rehashoption.) ๐source file_name,\. file_nameโ reads the named file and executes the statements inside it. On Windows, you can specify path name separators as/or\\.status,\sโ hands you status information about the connection and the server you're using. If you're running in--safe-updatesmode,statusalso prints the values for the mariadb variables that affect your queries. ๐system command,\! commandโ executes the given command using your default command interpreter.
Unix only, once again ๐ธ
tee [file_name],\T [file_name]โ by using the--teeoption when you invoke mariadb, you can log statements and their output. All the data shown on screen gets appended into a given file. Genuinely so useful for debugging too. mariadb flushes results to the file after each statement, right before it prints its next prompt. Tee functionality works only in interactive mode.
You can turn this feature on interactively with the tee command. Without a parameter, the previous file is used. The tee file can be disabled with the notee command. Running tee again re-enables logging. ๐ฅ
use db_name,\u db_nameโ usesdb_nameas the default database. Slay, now you're in.warnings,\Wโ enables display of warnings after each statement (if there are any).
okay so here are a few tips about the pager command, because this thing is lowkey iconic once you get it ๐
- You can use it to write to a file, and then the results go only to the file:
mariadb> pager cat > /tmp/log.txt
You can also pass any options for the program that you want to use as your pager:
mariadb> pager less -n -i -S
- In the example above, note the
-Soption. You may find it very useful for browsing wide query results. Sometimes a very wide result set is difficult to read on the screen. The-Soption tolesscan make the result set much more readable because you can scroll it horizontally using the left-arrow and right-arrow keys. You can also use-Sinteractively withinlessto switch the horizontal-browse mode on and off. For more information, read thelessmanual page:
shell> man less
- The
-Fand-Xoptions may be used withlessto cause it to exit if output fits on one screen, which is convenient when no scrolling is necessary:
mariadb> pager less -n -i -S -F -X
- You can specify very complex pager commands for handling query output:
mariadb> pager cat | tee /dr1/tmp/res.txt \
| tee /dr2/tmp/res2.txt | less -n -i -S
In this example, the command would send query results to two files in two different directories on two different file systems mounted on /dr1 and /dr2, yet still display the results onscreen via less. it's giving multitasking main character energy ๐
You can also combine the tee and pager functions. Have a tee file enabled and pager set to less, and you are able to browse the results using the less program and still have everything appended into a file at the same time. The difference between the Unix tee used with the pager command and the mariadb built-in tee command is that the built-in tee works even if you do not have the Unix tee available. The built-in tee also logs everything that is printed on the screen, whereas the Unix tee used with pager does not log quite that much. Additionally, tee file logging can be turned on and off interactively from within mariadb. This is useful when you want to log some queries to a file, but not others. โจ
okay so real talk, the prompt command is the one that reconfigures your default mariadb> prompt, and bestie, it is SO customizable. ๐ The string you give it can contain the following special sequences โ and yes, we're doing all of them, no skipping:
\cโ a counter that increments for each statement you issue ๐ข\Dโ the full current date ๐\dโ the default database\hโ the server host\lโ the current delimiter (new in 5.1.12) โจ\mโ minutes of the current time\nโ a newline character\Oโ the current month in three-letter format (Jan, Feb, ...)\oโ the current month in numeric format\Pโ am/pm\pโ the current TCP/IP port or socket file\Rโ the current time, in 24-hour military time (0โ23) โฐ\rโ the current time, standard 12-hour time (1โ12)\Sโ semicolon\sโ seconds of the current time\tโ a tab character\Uโ your full user_name@host_name account name ๐ซถ\uโ your user name\vโ the server version\wโ the current day of the week in three-letter format (Mon, Tue, ...)\Yโ the current year, four digits\yโ the current year, two digits\_โ a space\โ a space (a space follows the backslash)\'โ single quote\"โ double quote\\โ a literal "" backslash character\xโ x, for any "x" not listed above
And there are, like, four whole ways to set this thing. Pick your fighter:
- Use an environment variable. Set the
MYSQL_PS1environment variable to a prompt string. For example:
shell> export MYSQL_PS1="(\u@\h) [\d]> "
- Use a command-line option. Set the
--promptoption on the command line tomariadb. For example:
shell> mariadb --prompt="(\u@\h) [\d]> "
(user@host) [database]>
- Use an option file. Set the
promptoption in the[mariadb]group of any MariaDB option file, like/etc/my.cnfor the.my.cnffile in your home directory. For example:
[mariadb]
prompt=(\\u@\\h) [\\d]>\\_
In this example, notice that the backslashes are doubled. If you set the prompt using the prompt option in an option file, it's advisable to double the backslashes when you're using the special prompt options. There's some overlap in the set of allowable prompt options and the set of special escape sequences that are recognized in option files. And that overlap can cause you problems if you use single backslashes. For example, \s is interpreted as a space rather than as the current seconds value. ๐ญ The following example shows how to define a prompt within an option file to include the current time in HH:MM:SS> format:
[mariadb]
prompt="\\r:\\m:\\s> "
- Set the prompt interactively. You can change your prompt on the fly by using the
prompt(or\R) command. For example:
mariadb> prompt (\u@\h) [\d]>\_
PROMPT set to '(\u@\h) [\d]>\_'
(user@host) [database]>
(user@host) [database]> prompt
Returning to default PROMPT of mariadb>
mariadb>
๐ธ MARIADB SERVER-SIDE HELP ๐ธ
mariadb> help search_string
If you hand an argument to the help command, mariadb uses it as a search string to access server-side help. For this to actually work properly, the help tables in the mysql database need to be initialized with help topic information. (iykyk)
If there's no match for your search string, the search just... fails:
mariadb> help me
Nothing found
Please try to run 'help contents' for a list of all accessible topics
Use help contents to see a list of the help categories:
mariadb> help contents
You asked for help about help category: "Contents"
For more information, type 'help <item>', where <item> is one of the
following categories:
Account Management
Administration
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Language Structure
Plugins
Storage Engines
Stored Routines
Table Maintenance
Transactions
Triggers
If your search string matches multiple items, mariadb shows you a list of the matching topics:
mariadb> help logs
Many help items for your request exist.
To make a more specific request, please type 'help <item>',
where <item> is one of the following topics:
SHOW
SHOW BINARY LOGS
SHOW ENGINE
SHOW LOGS
And if you use a topic as the search string, you get the help entry for that topic:
mariadb> help show binary logs
Name: 'SHOW BINARY LOGS'
Description:
Syntax:
SHOW BINARY LOGS
SHOW MASTER LOGS
Lists the binary log files on the server. This statement is used as
part of the procedure described in [purge-binary-logs], that shows how
to determine which logs can be purged.
mariadb> SHOW BINARY LOGS;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000015 | 724935 |
| binlog.000016 | 733481 |
+---------------+-----------+
like. the way that it just tells you things. we love a self-documenting queen ๐
๐พ EXECUTING SQL STATEMENTS FROM A TEXT FILE ๐พ
So normally you're just vibing in the mariadb client interactively, like this:
shell> mariadb db_name
But bestie, you can also just yeet your SQL statements into a file and tell mariadb to read its input from there. To do that, make a text file called text_file with all the statements you wanna run. Then call mariadb like this:
shell> mariadb db_name < text_file
And if you drop a USE db_name statement as the very first line in that file, you don't even need to name the database on the command line:
shell> mariadb < text_file
Already inside mariadb? No problem, you can run an SQL script file with the source command or the \. command:
mariadb> source file_name
mariadb> \. file_name
Sometimes you want your script to show the user some progress info, and for that you can sneak in statements like this:
SELECT '<info_to_display>' AS ' ';
That statement right there outputs <info_to_display>. โจ
You can also launch mariadb with the --verbose option, which makes every statement get displayed before the result it produces. So you see the receipts. ๐
Oh, and heads up: mariadb ignores Unicode byte order mark (BOM) characters at the beginning of input files. Having a BOM does not make mariadb switch up its default character set. If you actually want to change that, invoke mariadb with an option like --default-character-set=utf8.
๐ธ MARIADB TIPS ๐ธ
This section is basically the little bag of tricks that'll help you use mariadb way more effectively. Let's go. ๐ซถ
๐ Displaying Query Results Vertically ๐
Some query results are just so much more readable when you show them vertically instead of in the usual horizontal table format. You get vertical output by ending the query with \G instead of a semicolon. For example, longer text values that include newlines are often way easier to read with vertical output:
mariadb> SELECT * FROM mails WHERE LENGTH(txt) < 300 LIMIT 300,1\G
*************************** 1. row ***************************
msg_nro: 3068
date: 2000-03-01 23:29:50
time_zone: +0200
mail_from: Monty
reply: monty@no.spam.com
mail_to: "Thimble Smith" <tim@no.spam.com>
sbj: UTF-8
txt: >>>>> "Thimble" == Thimble Smith writes:
Thimble> Hi. I think this is a good idea. Is anyone familiar
Thimble> with UTF-8 or Unicode? Otherwise, I'll put this on my
Thimble> TODO list and see what happens.
Yes, please do that.
Regards,
Monty
file: inbox-jani-1
hash: 190402944
1 row in set (0.09 sec)
๐ก๏ธ Using the --safe-updates Option ๐ก๏ธ
If you're a beginner, a genuinely useful startup option is --safe-updates (or --i-am-a-dummy, which does the exact same thing โ no judgement, the name is just iconic ๐). It's a lifesaver for those moments where you might have typed a DELETE FROM tbl_name statement and forgotten the WHERE clause. Normally that statement nukes all the rows from the table. With --safe-updates, you can only delete rows by specifying the key values that identify them. It's literally there to prevent accidents.
When you use the --safe-updates option, mariadb issues the following statement when it connects to the MariaDB server:
SET sql_safe_updates=1, sql_select_limit=1000, sql_max_join_size=1000000;
That SET statement has these effects:
- You are not allowed to execute an
UPDATEorDELETEstatement unless you specify a key constraint in theWHEREclause or provide aLIMITclause (or both). For example:
UPDATE tbl_name SET not_key_column=val WHERE key_column=val;
UPDATE tbl_name SET not_key_column=val LIMIT 1;
- The server limits all large
SELECTresults to 1,000 rows unless the statement includes aLIMITclause. - The server aborts multiple-table
SELECTstatements that probably need to examine more than 1,000,000 row combinations.
Wanna set limits that aren't 1,000 and 1,000,000? You can override the defaults with the --select-limit and --max-join-size options:
shell> mariadb --safe-updates --select-limit=500 --max-join-size=10000
๐ Disabling mariadb Auto-Reconnect ๐
Okay so here's the tea. If the mariadb client loses its connection to the server while it's sending a statement, it immediately and automatically tries to reconnect once to the server and send the statement again. But even if mariadb manages to reconnect, your first connection has ended and all your previous session objects and settings are gone: temporary tables, the autocommit mode, and user-defined and session variables. Also, any current transaction rolls back. This behavior may be dangerous for you โ like in this example, where the server got shut down and restarted between the first and second statements without you knowing it:
mariadb> SET @a=1;
Query OK, 0 rows affected (0.05 sec)
mariadb> INSERT INTO t VALUES(@a);
ERROR 2006: MariaDB server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: test
Query OK, 1 row affected (1.30 sec)
mariadb> SELECT * FROM t;
+------+
| a |
+------+
| NULL |
+------+
1 row in set (0.05 sec)
The @a user variable has been lost along with the connection, and after the reconnection it is undefined. ๐ญ So if it's important to you that mariadb terminates with an error when the connection has been lost, start the mariadb client with the --skip-reconnect option. Protect your peace.
๐ COPYRIGHT ๐
Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc., 2010-2025 MariaDB Foundation
This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.
This documentation is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA or see http://www.gnu.org/licenses/.
๐ NOTES ๐
- Bug#25946 โ
http://bugs.mysql.com/bug.php?id=25946
๐ SEE ALSO ๐
For more information, please refer to the MariaDB Documentation, available online at https://mariadb.com/docs/
๐ AUTHOR ๐
MariaDB Foundation (http://www.mariadb.org/).
And that's a wrap, bestie! This whole page is from MariaDB 11.8, dated 5 March 2025, and it's the MARIADB(1) manual page โ so if anyone asks where you learned all this, you know exactly what to cite. Slay, go run some queries. ๐โจ
๐ฆ where this page comes from
- arch rolling: mariadb 13.0.2-2 ยท GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 ยท GPL-2.0-only
- fedora 44: mariadb12.3-embedded 3:12.3.2-2.fc44 ยท ( GPL-2.0-only OR Apache-2.0 ) AND ( GPL-2.0-or-later OR Apache-2.0 ) AND BSD-2-Clause AND BSD-3-Clause AND CC-BY-4.0 AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ( GPL-3.0-or-later WITH Bison-exception-2.2 ) AND LGPL-2.0-only AND LGPL-2.0-or-later AND LGPL-2.1-only AND LGPL-2.1-or-later AND OpenSSL AND MIT AND OFL-1.1 AND CC0-1.0 AND PHP-3.0 AND PHP-3.01 AND zlib AND dtoa AND FSFAP AND blessing AND Info-ZIP AND Boehm-GC
- fedora 44: mariadb12.3-embedded 3:12.3.2-2.fc44 ยท ( GPL-2.0-only OR Apache-2.0 ) AND ( GPL-2.0-or-later OR Apache-2.0 ) AND BSD-2-Clause AND BSD-3-Clause AND CC-BY-4.0 AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND ( GPL-3.0-or-later WITH Bison-exception-2.2 ) AND LGPL-2.0-only AND LGPL-2.0-or-later AND LGPL-2.1-only AND LGPL-2.1-or-later AND OpenSSL AND MIT AND OFL-1.1 AND CC0-1.0 AND PHP-3.0 AND PHP-3.01 AND zlib AND dtoa AND FSFAP AND blessing AND Info-ZIP AND Boehm-GC
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms