LinuxCommandLibrary

mariadb

Access and manage MariaDB databases

TLDR

Connect to a specific MariaDB database

$ mariadb [db_name]
copy

Connect to a specific MariaDB database using username and password
$ mariadb [[-u|--user]] [user_name] [[-p|--password]] [your_password] [db_name]
copy

Show warnings after every statement in interactive and batch mode
$ mariadb --show-warning
copy

Display less verbose outputs (can be used multiple times to produce less output)
$ mariadb [-s|-ss|-sss|--silent]
copy

Execute SQL statements from a script file
$ mariadb < [path/to/script.sql] [db_name] > [path/to/output.tab]
copy

Check memory and open file usage at exit
$ mariadb --debug-check
copy

Connect using a socket file for local connections
$ mariadb [[-S|--socket]] [path/to/socket_name]
copy

Display help
$ mariadb [[-?|--help]]
copy

SYNOPSIS

mariadb [options] [db_name]

PARAMETERS

-?, --help
    Display help message and exit

--version, -V
    Show version information

-h, --host=name
    Connect to specified host (default: localhost)

-P, --port=port_num
    TCP/IP port number (default: 3306)

-S, --socket=path
    Unix socket file or Windows named pipe

-u, --user=name
    MariaDB username (default: login name)

-p, --password[=name]
    Password; if omitted, prompts interactively

-D, --database=name
    Database to use upon connection

-e, --execute=statement
    Execute SQL statement and exit

--connect_timeout=seconds
    Timeout for connection establishment

-t, --table
    Display output in table format

--auto-rehash
    Enable automatic rehashing for tab completion

--ssl-mode=mode
    SSL connection mode (REQUIRED, PREFERRED, etc.)

-v, --verbose
    Verbose output

--comments
    Preserve SQL comments in statements

DESCRIPTION

The mariadb command is the primary client tool for interacting with a MariaDB database server, an open-source fork of MySQL designed for enhanced performance and community-driven development. It enables users to connect to a local or remote MariaDB instance, execute SQL queries interactively, run scripts from files, or perform one-off statements via batch mode.

Upon invocation, it prompts for SQL input if no statements are provided, supporting commands like SELECT, INSERT, UPDATE, and administrative tasks such as CREATE DATABASE or SHOW TABLES. Features include command history (via arrow keys), auto-completion (double-tab), output formatting (tabular, vertical, etc.), and variables for scripting. Connection details like host, port, user credentials, and default database are configurable via options or ~/.my.cnf files.

Ideal for database administrators, developers, and automation scripts, it mirrors MySQL client syntax for easy migration. Secure practices recommend avoiding plaintext passwords on the command line to prevent exposure in process lists. Supports SSL/TLS for encrypted connections and compression for bandwidth savings. Exit with \q, exit, or Ctrl+D.

CAVEATS

Passwords on command line appear in process lists; use ~/.my.cnf or interactive prompt. Not for starting the server (use mariadbd). Limited to client functions; no direct server control.

CONFIGURATION FILES

Reads options from /etc/my.cnf, ~/.my.cnf in INI format under [client] or [mariadb] sections.
Example:
[client]
host=localhost
user=root

COMMON EXAMPLES

mariadb -u root -p mydb — Connect interactively to 'mydb'.

echo 'SELECT * FROM users;' | mariadb -u root mydb — Batch query.

mariadb -e "SHOW DATABASES;" — Quick list databases.

HISTORY

Originated as MySQL client; renamed mariadb in MariaDB 10.2 (2017) to distinguish from Oracle-owned MySQL. MariaDB project forked from MySQL 5.1 in 2009 by Monty Program AB for open governance.

SEE ALSO

mysql(1), mysqld(8), mariadbd(8), mariadb-dump(1), mariadb-admin(1)

Copied to clipboard