LinuxCommandLibrary

mariadb

command-line client for MariaDB database server

TLDR

Connect to database

$ mariadb -u [user] -p [database]
copy
Connect to remote server
$ mariadb -h [hostname] -u [user] -p [database]
copy
Execute SQL command
$ mariadb -u [user] -p -e "[SELECT * FROM table]" [database]
copy
Execute SQL file
$ mariadb -u [user] -p [database] < [script.sql]
copy
Connect with socket
$ mariadb -S [/var/run/mysqld/mysqld.sock] -u [user] -p
copy
Export query to file
$ mariadb -u [user] -p -e "[SELECT * FROM table]" [database] > [output.txt]
copy
Connect with SSL
$ mariadb --ssl -u [user] -p [database]
copy

SYNOPSIS

mariadb [-u user] [-p] [-h host] [-e command] [options] [database]

DESCRIPTION

mariadb is the command-line client for MariaDB database server. It provides an interactive SQL shell and can execute commands from files or command line.
The client connects to MariaDB or MySQL servers, as MariaDB maintains wire protocol compatibility. Interactive mode provides command history, editing, and tab completion.
Batch mode (-B) produces tab-separated output suitable for scripting. Combined with -N to skip headers, output can be processed by other tools.
Safe updates mode prevents UPDATE and DELETE without WHERE clauses, protecting against accidental data loss.
SSL connections encrypt traffic between client and server. Certificate verification can be configured for production environments.
The client supports pipelining SQL from files, enabling automated database migrations and backups restoration.

PARAMETERS

-u USER, --user USER

Username for connection.
-p[PASSWORD], --password[=PASS]
Prompt for or specify password.
-h HOST, --host HOST
Server hostname.
-P PORT, --port PORT
Server port.
-S SOCKET, --socket SOCKET
Unix socket file.
-D DB, --database DB
Database to use.
-e CMD, --execute CMD
Execute command and exit.
-B, --batch
Batch mode (no formatting).
-N, --skip-column-names
Don't show column names.
-t, --table
Output as table.
--ssl
Enable SSL.
-A, --no-auto-rehash
Disable auto-completion.
--safe-updates
Prevent accidental large updates.
-v, --verbose
Verbose output.

CAVEATS

Password on command line visible in process list - use -p without argument. Large result sets may exhaust memory. Interactive features require readline.

HISTORY

MariaDB was created by Michael Widenius (Monty) after MySQL was acquired by Oracle in 2010. MariaDB is a community-developed fork designed to remain free and open-source. The mariadb client replaced mysql as the default client name in recent versions.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community