Command Line Integration
Call util, shell, and sandbox operations directly from the operating system shell with mariadb-shell -- <object> <operation>, passing positional, named, list, and dictionary arguments.
Command line integration runs one operation of a MariaDB Shell global object straight from the operating system shell, without a prompt and without writing a Python script. It maps a command such as
mariadb-shell mariadb://dba@localhost -- util dump-schemas shop --output-url=/backups/shop --threads=8to the Python call
util.dump_schemas("shop", {"outputUrl": "/backups/shop", "threads": 8})Use it in shell scripts, cron jobs, and CI pipelines, where a single operation with a few options is all you need.
Syntax
mariadb-shell [options] [URI] -- <object> [<nested object>] <operation> [arguments]Everything before
--is a normal shell option, such as the connection URI,--log-level, or--passwords-from-stdin.After
--come the object, the operation, and its arguments. No other shell options can follow.Operations that work on a server, such as dumps and diagnostics, use the global session from the URI. Operations that don't need a server, such as
sandbox deployorshell list-credential-helpers, need no URI.
The shell runs the operation, prints its return value, if any, and exits. Lists and dictionaries are printed as JSON.
Available Objects and Operations
util
copy-instance, copy-schemas, copy-tables, dump-instance, dump-schemas, dump-tables, export-table, import-table, load-dump
util debug
collect-diagnostics, collect-high-load-diagnostics, collect-slow-query-diagnostics
shell
status, list-credential-helpers, list-credentials, store-credential, delete-credential, delete-all-credentials, list-secrets, read-secret, store-secret, delete-secret, delete-all-secrets, list-sql-handlers
shell options
set-persist, unset-persist
sandbox
deploy, start, stop, kill, delete, vendor, version, get-path
Other global objects, such as mysql and plugins, aren't available on the command line. Plugins can make their own functions available by registering them with cli=True. See Plugins.
A nested object follows its parent after a space: write util debug collect-diagnostics and shell options set-persist, not util.debug or shell.options.
Getting Help
Add --help at any level to list what's available or to show the arguments of an operation:
The help of an operation shows its syntax in command line form, such as util dump-schemas <schemas> --outputUrl=<str> [<options>], and lists each option with its type.
Naming Styles
Operation and option names can be written in camelCase, as in the help, or in kebab-case. The following commands are equivalent:
Arguments
Arguments are positional or named. Positional arguments fill the parameters of the operation in order. Named arguments, which start with --, become the keys of the options dictionary that most operations take as their last parameter.
Positional Arguments
A positional argument is a single value. The shell converts it to the type that the parameter expects:
shop, "Desk lamp"
String. Quote values that contain spaces, as your operating system shell requires.
42
Integer
0.5
Float
true, false, 1, 0
Boolean
null
null. Only a parameter that accepts any type takes it; a parameter with a declared type, such as a string or an integer, rejects it.
[1,"a"], {"key":1}
List or dictionary, written as JSON. Quote it so that the operating system shell passes it unchanged.
A value that is valid JSON takes its JSON type, and anything else is a string: - is the string -, not null.
Named Arguments
A named argument has one of these forms:
--name=value
Sets the option to the value.
--name value
Same as --name=value.
--name
Sets a Boolean option to true.
--name:type=value
Sets the option and states the type of the value explicitly. The types are str, int, uint, float, bool, null, list, dict, and json.
The shell checks each named argument against the options that the operation accepts. An unknown option or a value of the wrong type stops the call with exit code 10:
Without an explicit type, the shell converts the value to the type that the option expects. The explicit type matters for options that accept values of more than one type.
Lists
For a parameter or option that takes a list, pass the items separated by commas. To use a comma inside an item, escape it as \, or quote the item:
You can also repeat the option. Each occurrence adds items to the list:
A JSON array works as well. Quote it so that the operating system shell passes it unchanged:
Dictionaries
For an option that takes a dictionary, pass each entry as key=value, and repeat the option for more entries. The following command imports a CSV file into shop.product and doubles the value of the third field on the way:
You can also pass the whole dictionary as JSON, quoted so that the operating system shell passes it unchanged. The entries are merged with any given as key=value. A key can contain dots, as in the schema.table keys of the dump where option:
Grouping Named Arguments
Named arguments at the end of the command go into the last parameter. When an operation takes more than one dictionary, enclose the named arguments for an earlier one in braces, separated by spaces. The braces are separate arguments and must be quoted in most operating system shells:
Examples
Dump Schemas
Load a Dump
Export a Table to CSV
Collect Diagnostics
See Diagnostics Utilities for the options.
Show the Connection Status
The output is the same as that of \status. See Shell Commands.
Persist a Shell Option
Manage Sandboxes
See Sandbox Instances.
Exit Codes
0
The operation succeeded.
1
The operation failed, for example because of a server error or an invalid path.
10
The command line was invalid: an unknown object, operation, or option, or a value of the wrong type.
For other exit codes of the shell, see Batch Execution.
This page is licensed: GPLv2
Last updated
Was this helpful?

