MARIADB(1)
๐ MARIADB(1) โ the MariaDB command-line tool ๐
MariaDB Database System ยท MARIADB(1)
okay bestie, sit down, hydrate, because this is the manual page for mariadb, and she is iconic. ๐
โจ NAME โจ
mariadb โ the MariaDB command-line tool (mysql is now a symlink to mariadb) ๐ซถ
๐ธ SYNOPSIS ๐ธ
mariadb [options] db_name
๐ฆ DESCRIPTION ๐ฆ
mariadb is a simple SQL shell (with GNU readline capabilities, so yes, she has โจline editingโจ). She supports both interactive and non-interactive use, like a true multi-hyphenate. When you use her interactively, query results come out in an ASCII-table format. When you use her non-interactively (say, as a filter), the result shows up in tab-separated format. Want a different vibe? The output format can be changed using command options. ๐ฅ
If you're having problems because of insufficient memory for large result sets, use the --quick option. That forces mariadb to retrieve results from the server a row at a time, instead of pulling the entire result set and buffering it in memory before displaying it. It does this by returning the result set using the mariadb_use_result() C API function in the client/server library rather than mysql_store_result(). No cap, that's the whole trick.
Using mariadb is very easy. Invoke her from the prompt of your command interpreter like this:
shell> mariadb db_name
Or:
shell> mariadb --user=user_name --password=your_password db_name
Then type an SQL statement, end it with โ;โ, \g, or \G and press Enter. That's it, that's the ritual. ๐
Typing Control-C causes mariadb to attempt to kill the current statement. If this cannot be done, or Control-C is typed again before the statement is killed, mariadb exits. So likeโฆ first Ctrl-C is a polite request, second one is a breakup. ๐ญ
You can execute SQL statements in a script file (batch file) like this:
shell> mariadb db_name < script.sql > output.tab
๐ MARIADB OPTIONS ๐
mariadb supports the following options, which can be specified on the command line or in the [mariadb], [client], [client-server] or [client-mariadb] option file groups. mariadb also supports the options for processing option files. Let's go through every single one, no skipping, we don't do that here. ๐
--help,-?,-Iโ Display a help message and exit. Your emotional support flag.--abort-source-on-errorโ Abortsource filenameoperations in case of errors.--auto-rehashโ Enable automatic rehashing. This option is on by default, which enables database, table, and column name completion. Use--disable-auto-rehash,--no-auto-rehash, or--skip-auto-rehashto disable rehashing. That causesmariadbto start faster, but you must issue therehashcommand if you want to use name completion.
To complete a name, enter the first part and press Tab. If the name is unambiguous, mariadb completes it. Otherwise, you can press Tab again to see the possible names that begin with what you have typed so far. Completion does not occur if there is no default database. (Rude, honestly, but okay. ๐)
--auto-vertical-outputโ Automatically switch to vertical output mode if the result is wider than the terminal width.--batch,-Bโ Print results using tab as the column separator, with each row on a new line. With this option,mariadbdoes not use the history file.
Batch mode results in nontabular output format and escaping of special characters. Escaping may be disabled by using raw mode; see the description for the --raw option.
--binary-modeโ Binary mode allows certain character sequences to be processed as data that would otherwise be treated with a special meaning by the parser. Specifically, this switch turns off parsing of all client commands except\CandDELIMITERin non-interactive mode (i.e., when binary mode is combined with either 1) piped input, 2) the--batchmariadb option, or 3) the'source'command). Also, in binary mode, occurrences of'\r\n'and ASCII'\0'are preserved within strings, whereas by default,'\r\n'is 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.--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(discard comments), enable with--comments(preserve comments).--compress,-Cโ Compress all information sent between the client and the server if both support compression.--connect-timeout=secondsโ Set the number of seconds before connection timeout. (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 and memory and CPU usage statistics when the program exits.--default-auth=nameโ Default authentication client-side plugin to use.--default-character-set=charset_nameโ Usecharset_nameas the default character set for the client and connection.
A common issue that can occur when the operating system uses utf8 or another multi-byte character set is that output from the mariadb client is formatted incorrectly, due to the fact that the MariaDB client uses the latin1 character set by default. You can usually fix such issues 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 has been read. Must be given as first option.--defaults-file=filenameโ Setfilenameas the file to read default options from, override global defaults files. Must be given as 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. Exists only for MySQL compatibility. ๐ She's retired but she's still on the roster.--execute=statement,-e statementโ Execute the statement and quit. Disables--forceand history file. The default output format is like that produced with--batch.--force,-fโ Continue 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. Allows one to have spaces (including tab characters and new line characters) between function name and'('. The drawback is that this causes built in functions to become reserved words.--init-command=strโ SQL Command to execute when connecting to the MariaDB server. Will automatically be re-executed when reconnecting. She remembers. ๐ง--line-numbersโ Write line numbers for errors. Disable this with--skip-line-numbers.--local-infile[={0|1}]โ Enable or disableLOCALcapability forLOAD DATA INFILE. With no value, the option enablesLOCAL. The option may be given as--local-infile=0or--local-infile=1to explicitly disable or enableLOCAL. EnablingLOCALhas no effect if the server does not also support it.--max-allowed-packet=numโ Set the maximum packet length to send to or receive from the server. (Default value is16MB, largest1GB.)--max-join-size=numโ Set the automatic limit for rows in a join when using--safe-updates. (Default value is1,000,000.)--named-commands,-Gโ Enable namedmariadbcommands. Long-format commands are allowed, not just short-format commands. For example,quitand\qboth are 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 is16KB.)--no-auto-rehash,-Aโ This has the same effect as--skip-auto-rehash. See the description for--auto-rehash.--no-beep,-bโ Do not beep when errors occur. (The beep was NOT serving anyway. ๐)--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 those that occur while the default database is the one named on the command line. This filtering is limited, and based only onUSEstatements. This is useful for skipping updates to other databases in the binary log.--pager[=command]โ Use the given command for paging query output. If the command is omitted, 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โ, discusses output paging further.--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 omit the password value following the--passwordor-poption on the command line,mariadbprompts for one.
โ ๏ธ Specifying a password on the command line should be considered insecure. You can use an option file to avoid giving the password on the command line.
--pipe,-Wโ On Windows, connect to the server via a named pipe. This option applies only 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 default to, in order of preference,my.cnf,$MYSQL_TCP_PORT,/etc/services, built-in default (3306). Forces--protocol=tcpwhen specified on the command line without other connection properties.--print-defaultsโ Print the program argument list and exit. This must be given as the first argument.--progress-reportsโ bestie this is your little โจprogress barโจ for the long-haul commands (think a big dramaticALTER TABLE). It's on by default, so if you're over it, hit it with--skip-progress-reportsto turn it off.--prompt=format_strโ sets your prompt to whatever format you want. All the special little sequences you can stuff into that format are listed over in the section called โMARIADB COMMANDSโ. go look, it's cute.--protocol={TCP|SOCKET|PIPE|MEMORY}โ this picks the connection protocol for talking to the server. Super handy when your other connection params would normally make it pick a protocol that isn't the one you actually want. you're in charge, not the defaults.--quick,-qโ do not cache each query result, just print every row the second it arrives. Heads up though: this can slow the server down if the output gets suspended. And with this option on,mariadbdoesn't touch the history file at all. ๐--raw,-rโ okay so for tabular output, the โboxingโ around columns is what lets you tell one column value apart from another. For nontabular output (like what you get in batch mode, or when--batchor--silentis given), special characters get escaped so you can still spot them easily โ newline, tab, NUL and backslash come out as\n,\t,\0and\\. The--rawoption kills that escaping entirely.
Here's the glow-up, tabular vs nontabular vs raw mode:
% 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. It's enabled by default, and to disable it you use--skip-reconnector--disable-reconnect.--safe-updates,--i-am-a-dummy,-Uโ only lets through thoseUPDATEandDELETEstatements that say which rows they're modifying by using key values. If you set this in an option file, you can override it by using--safe-updateson the command line. The section called โMARIADB TIPSโ has more tea on this one. ๐ซถ--secure-authโ do not send passwords to the server in the old (pre-4.1.1) format. This blocks connections except for servers that use the newer password format. old format? we don't know her.--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 pop up after every statement, if there are any. Works in both interactive and batch mode. ๐--sigint-ignoreโ ignoresSIGINTsignals (which is typically what happens when you type Control-C). no more accidental rage-quitting mid-query.--silent,-sโ silent mode, i.e. produce less output. You can give this option multiple times to produce less and less and less output. This one gives you nontabular output format plus escaping of special characters โ and that escaping can be turned off with raw mode, see the--rawdescription above. ๐--skip-auto-rehashโ disables automatic rehashing. It's a synonym for--disable-auto-rehash.--skip-column-names,-Nโ don't write column names in results. just the data, bestie.--skip-line-numbers,-Lโ don't write line numbers for errors. So useful when you're comparing 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. It forces--protocol=socketwhen you specify it on the command line without other connection properties; on Windows, it forces--protocol=pipe.--sslโ enables SSL for the connection (it gets automatically enabled with other flags anyway). Disable it with--skip-ssl.--ssl-ca=nameโ CA file in PEM format (check the OpenSSL docs, and yes it 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, so turn it on yourself if you want that security moment. ๐ฅ--table,-tโ displays output in table format. That's the default for interactive use, but you can also use it to get table output in batch mode.--tee=file_nameโ appends a copy of the output to the given file. Only works in interactive mode, just so you know. The section called โMARIADB COMMANDSโ spills more tea on tee files.--unbuffered,-nโ flushes the buffer after each query. instant gratification only. โจ--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. You can give this multiple times for more and more and MORE output. (For example,-v -v -vproduces table output format even in batch mode. iconic.)--version,-Vโ displays version information and exits.--vertical,-Eโ prints query output rows vertically (one line per column value). Without this option 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. it's giving patience.--xml,-Xโ produces XML output. When--xmlis used withmariadb, the output matches that ofmariadb-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.)
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. To pick a different file, set the value of the MARIADB_HISTFILE environment variable. The environment variable MYSQL_HISTFILE will be used if MARIADB_HISTFILE isn't present.
okay real talk ๐ the .mariadb_history file should be protected with a restrictive access mode, because sensitive information might get written into it โ like the text of SQL statements that contain passwords. protect your girl.
If you do not want to maintain a history file, first remove .mariadb_history if it exists, and then use either of the following techniques:
- Set the
MARIADB_HISTFILEvariable to/dev/null. To make that setting kick in every 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 only need to do this once. ๐
๐ MARIADB COMMANDS ๐
mariadb sends every SQL statement you issue off to the server to be executed. But there's also a whole set of commands that mariadb itself interprets. For the full list of those commands, type help or \h at the mariadb> prompt:
okay so you type help and this whole menu drops ๐
here's literally what it prints, no edits:
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'
notable detail bestie: all text commands have to be first on the line and end with ;. That's the whole rule. Don't fight it.
Every command comes in a long form and a short form. The long form is not case sensitive. The short form is. The long form can be followed by an optional semicolon terminator โ the short form should not be. And using short-form commands inside multi-line /* ... */ comments? Not supported. Nope. Don't do it. ๐
โจ the commands, one by one โจ
help [arg],\h [arg],\? [arg],? [arg]โ Drops a help message listing all the available mariadb commands. Give it an argument and mariadb uses that as a search string to go grab server-side help. More on that in the section called โMARIADB SERVER-SIDE HELPโ.charset charset_name,\C charset_nameโ Switches the default character set and fires off aSET NAMESstatement. Why do we care? Because it keeps the character set synchronized between client and server if mariadb is running with auto-reconnect enabled (which, btw, is not recommended ๐ฅ) โ the charset you picked is what gets used for reconnects.clear,\cโ Clears your current input. Use it when you change your mind about the statement you were typing. The digital equivalent of deleting the paragraph. ๐connect [db_name host_name]],\r [db_name host_name]]โ Reconnects to the server. The optional database name and host name arguments let you specify the default database or the host where the server's running. Leave them out and the current values get used instead.delimiter str,\d strโ Changes the string mariadb treats as the separator between SQL statements. The default is the semicolon character (;), yes, that little guy.
The delimiter can be handed over as an unquoted or a quoted argument. Quoting works with either a single quote (') or a double quote ("). Wanna put a quote inside a quoted string? Either quote the string with the other quote character, or escape the quote with a backslash (\). Avoid backslashes outside of quoted strings though, because backslash is the escape character for MariaDB. For an unquoted argument, the delimiter gets read up to the first space or the end of the line. For a quoted argument, it's read up to the matching quote on the line.
Now the plot twist: when the delimiter mariadb recognizes 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. That server-side behaviour matters for multiple-statement execution, and for parsing the body of stored procedures and functions, triggers, and events.
edit,\eโ Edits the current input statement. mariadb peeks at the values of theEDITORandVISUALenvironment variables to figure out which editor to use. If neither variable is set, the default editor isvi.editworks only in Unix.ego,\Gโ Sends the current statement to the server to be executed, and shows the result in vertical format. (Yes this is the one you spam when a wide table looks like a crime scene.)exit,\qโ Exits mariadb.go,\gโ Sends the current statement to the server to be executed.nopager,\nโ Disables output paging. See the description forpager. Works only in Unix.notee,\tโ Disables copying output into the tee file. See the description fortee.nowarning,\wโ Enables display of warnings after each statement. (That is word for word what the page says, bestie. I'm just the messenger. ๐)pager [command],\P [command]โ Enables output paging. Use the--pageroption when you launch mariadb and you can browse or search query results in interactive mode using Unix programs likeless,more, or any other similar program. Give the option no value and mariadb checks thePAGERenvironment variable and sets the pager to that. Pager functionality works only in interactive mode.
You can flip output paging on interactively with the pager command and off with nopager. The command takes an optional argument; hand it one and the paging program gets set to that. With no argument, the pager is set to the pager that was set on the command line, or to stdout if no pager was specified.
Output paging works only in Unix, because it uses the popen() function, which does not exist on Windows. On Windows you can use the tee option instead to save query output โ although it's not as convenient as pager for browsing output in some situations.
print,\pโ Prints the current input statement without executing it.prompt [str],\R [str]โ Reconfigures the mariadb prompt to the given string. The special character sequences you can use in the prompt are described later in this section. Givepromptno argument and mariadb resets the prompt to the default,mariadb>.quit,\qโ Exits mariadb.rehash,\#โ Rebuilds the completion hash, which is the thing enabling 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โ Gives you status information about the connection and the server you're using. And 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. Works only in Unix.tee [file_name],\T [file_name]โ Use the--teeoption when you launch mariadb and you can log statements and their output. All the data displayed on the 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 enable this interactively with the tee command. No parameter? The previous file gets used. The tee file can be turned off with the notee command. Run tee again and logging comes right back on.
use db_name,\u db_nameโ Usesdb_nameas the default database.warnings,\Wโ Enables display of warnings after each statement (if there are any).
Here are a few tips about the pager command, because this thing is lowkey a superpower:
- You can use it to write to a file, and the results go only to the file:
mariadb> pager cat > /tmp/log.txt
You can also pass any options for the program you want to use as your pager: mariadb> pager less -n -i -S
- In that example above, clock the
-Soption. It's so useful for browsing wide query results. Sometimes a super wide result set is a nightmare to read on screen. The-Soption tolessmakes the result set way more readable, because you can scroll it horizontally with the left-arrow and right-arrow keys. You can also use-Sinteractively insidelessto switch horizontal-browse mode on and off. For more info, read thelessmanual page:
shell> man less
- The
-Fand-Xoptions can be used withlessto make it exit if the 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 sends query results to two files in two different directories on two different file systems mounted on /dr1 and /dr2 โ and still displays the results onscreen via less. Iconic behaviour honestly. ๐
You can also combine the tee and pager functions. Have a tee file enabled, set the pager to less, and boom: you can browse results with less and 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 don't have the Unix tee available. The built-in tee also logs everything that gets printed on the screen, whereas the Unix tee used with pager does not log quite that much. Plus, tee file logging can be turned on and off interactively from inside mariadb โ which is exactly what you want when you wanna log some queries to a file but not others. ๐ซถ
Okay bestie, real talk: the prompt command reconfigures the default mariadb> prompt. The string for defining the prompt can contain these special sequences:
\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 fulluser_name@host_nameaccount 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 backslash followed by 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
You can set the prompt in several ways:
- Use an environment variable. You can set the
MYSQL_PS1environment variable to a prompt string. For example:
shell> export MYSQL_PS1="(\u@\h) [\d]> "
- Use a command-line option. You can set the
--promptoption on the command line tomariadb. For example:
shell> mariadb --prompt="(\u@\h) [\d]> "
(user@host) [database]>
- Use an option file. You can set the
promptoption in the[mariadb]group of any MariaDB option file, such as/etc/my.cnfor the.my.cnffile in your home directory. For example:
[mariadb]
prompt=(\\u@\\h) [\\d]>\\_
In this example, note that the backslashes are doubled. If you set the prompt using the prompt option in an option file, it is advisable to double the backslashes when using the special prompt options. There is some overlap in the set of allowable prompt options and the set of special escape sequences that are recognized in option files. The overlap may 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 interactively 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 provide an argument to the help command, mariadb uses it as a search string to access server-side help. The proper operation of this command requires that the help tables in the mysql database be initialized with help topic information.
If there is no match for the search string, the search fails (sad, I know):
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 (the whole menu, slay):
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 the search string matches multiple items, mariadb shows a list of matching topics (pick your fighter):
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
Use a topic as the search string to see the help entry for that topic (main character energy):
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 |
+---------------+-----------+
๐ธ EXECUTING SQL STATEMENTS FROM A TEXT FILE ๐ธ
okay so normally you just vibe with mariadb interactively, like:
shell> mariadb db_name
but bestie, you can also just... put all your SQL statements in a file and tell mariadb to read from it instead. iconic. so: make a text file text_file with the statements you wanna run, then invoke it like this:
shell> mariadb db_name < text_file
and if you put a USE db_name statement as the very first statement in that file, you don't even need to name the database on the command line:
shell> mariadb < text_file
already in mariadb and wanna run a script file? use the source command or the \. command:
mariadb> source file_name
mariadb> \. file_name
sometimes you want your script to show progress info to the user ๐ซถ and for that you can drop in statements like this:
SELECT '<info_to_display>' AS ' ';
that statement outputs <info_to_display>. slay.
you can also invoke mariadb with the --verbose option, which makes every statement get displayed before its result shows up.
also bestie, mariadb ignores Unicode byte order mark (BOM) characters at the beginning of input files. a BOM being there does not make mariadb change its default character set. to change that, invoke mariadb with an option like --default-character-set=utf8.
๐ MARIADB TIPS ๐
this section is basically me handing you my tips & tricks so you can use mariadb way more effectively. you're welcome.
๐ฆ Displaying Query Results Vertically ๐ฆ
some query results are just so much more readable when they're shown vertically instead of the usual horizontal table format. you display a query vertically by ending it 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 ๐ญ). it saves you in those cases where you might have typed a DELETE FROM tbl_name statement and forgotten the WHERE clause. normally that statement deletes every row from the table. with --safe-updates, you can only delete rows by specifying the key values that identify them. it helps prevent accidents. we love a safety net.
when you use the --safe-updates option, mariadb issues this 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're 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 different from 1,000 and 1,000,000? you can override the defaults using the --select-limit and --max-join-size options:
shell> mariadb --safe-updates --select-limit=500 --max-join-size=10000
๐ Disabling mariadb Auto-Reconnect ๐
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 that statement again. but here's the tea โ โ even if mariadb succeeds in reconnecting, your first connection has ended and all your previous session objects and settings are lost: 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 was shut down and restarted between the first and second statements without you even knowing:
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 with the connection, and after the reconnection it is undefined. if it's important to you that mariadb terminates with an error when the connection has been lost, you can start the mariadb client with the --skip-reconnect option.
๐ 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 info, please refer to the MariaDB Documentation, available online at https://mariadb.com/docs/
๐ AUTHOR ๐
MariaDB Foundation (http://www.mariadb.org/).
and that's the whole page bestie, you made it to the end ๐ซถ this was MariaDB 11.8, dated 5 March 2025, and it's MARIADB(1) โ go forth and query, no cap ๐
โจ
๐ฆ where this page comes from
- alpine 3.24: mariadb-doc 11.8.9-r0 ยท GPL-2.0-only
- centos-stream 10: mariadb11.8 3:11.8.8-1.el10 ยท ( 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
- centos-stream 9: mariadb 3:11.8.8-1.module_el9+1370+ec5ecc2e ยท ( 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
- debian trixie: mariadb-client-core 1:11.8.6-0+deb13u1 ยท GPL-2.0-only
- fedora 43: mariadb11.8 3:11.8.8-1.fc43 ยท ( 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: mariadb 3:11.8.6-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: mariadb 3:11.8.8-3.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
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: mariadb-client 11.8.8-160000.1.1 ยท SUSE-GPL-2.0-with-FLOSS-exception
- opensuse-leap 16.0: mariadb-client 11.8.8-160000.1.1 ยท SUSE-GPL-2.0-with-FLOSS-exception
- opensuse-leap 16.0: mariadb-client 11.8.8-160000.1.1 ยท SUSE-GPL-2.0-with-FLOSS-exception
- opensuse-leap 16.0: mariadb-client 11.8.8-160000.1.1 ยท SUSE-GPL-2.0-with-FLOSS-exception
- ubuntu resolute: mariadb-client-core 1:11.8.6-5 ยท GPL-2.0-only
- ubuntu resolute: mariadb-client-core 1:11.8.6-5ubuntu0.1 ยท GPL-2.0-only
- ubuntu stonking: mariadb-client-core 1:11.8.9+ds-4ubuntu2 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms