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 --user [user_name] --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 [db_name] < [path/to/script.sql] > [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] [database]
mariadb {-e "SQL_COMMAND" | --execute="SQL_COMMAND"} [options] [database]
mariadb [options] < input_file.sql

PARAMETERS

-h, --host=hostname
    Specifies the hostname or IP address of the MariaDB server to connect to.

-P, --port=port_num
    Specifies the TCP/IP port number to use for the connection.

-u, --user=username
    Specifies the MariaDB username used to connect to the server.

-p, --password[=password]
    Prompts for a password if no password is provided. It's insecure to provide password directly on the command line.

-D, --database=db_name
    Specifies the default database to use once connected.

-e, --execute=SQL_COMMAND
    Executes the given SQL command and exits. Useful for scripting.

-s, --silent
    Produces less output. Omits column names and results are output with a tab separator.

-v, --verbose
    Produces more verbose output. Use multiple times for even more verbosity.

-V, --version
    Displays the version information and exits.

--socket=path
    Specifies the Unix socket file to use for connection on local host.

-B, --batch
    Prints results with a tab separator, one row per line. Does not use the history file.

-N, --skip-column-names
    Does not print column names in the output.

--html
    Produces HTML output.

--xml
    Produces XML output.

--help
    Displays a help message with all available options.

DESCRIPTION

mariadb is the official command-line client for interacting with MariaDB and MySQL database servers. It provides an interactive interface for executing SQL queries, managing databases and tables, and performing various administrative tasks directly from the terminal. This versatile tool allows users to connect to a database server, send SQL statements, retrieve results, and script database operations. It supports connections over TCP/IP or Unix sockets, and can be used in interactive mode for ad-hoc queries or in batch mode for automated scripts. Historically, it was known as mysql, but with the divergence of MariaDB from MySQL, the client binary was renamed to mariadb on many distributions to reflect its primary affiliation, while maintaining backward compatibility with MySQL servers. It's an indispensable tool for database administrators, developers, and anyone needing direct database interaction.

CAVEATS

Providing passwords directly on the command line using -pPASSWORD is highly insecure as it may be visible to other users via process lists (e.g., ps aux). It is recommended to use -p to be prompted for the password, or configure it in a secure configuration file (e.g., ~/.my.cnf). The behavior and available features of the mariadb client largely depend on the version and configuration of the MariaDB or MySQL server it connects to.

CONFIGURATION FILES

The mariadb client reads global options from files like /etc/my.cnf, and user-specific options from ~/.my.cnf. These files can contain connection details (host, user, password) and default client settings, enhancing security and convenience.

ENVIRONMENT VARIABLES

Several environment variables can influence the client's behavior, such as MYSQL_TCP_PORT for the default TCP port, and MYSQL_UNIX_PORT for the default Unix socket path.

HISTORY

The mariadb command-line client originated as the mysql client, which has been the primary interface for MySQL databases for many years. When MariaDB forked from MySQL, the development of the client also continued. On systems where MariaDB is the default database, the mysql command is often symlinked to mariadb, ensuring compatibility with existing scripts and user habits. This renaming reflects the shift in vendor and development focus, distinguishing it as the official client for MariaDB servers while maintaining functional equivalence and interoperability with MySQL servers.

SEE ALSO

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

Copied to clipboard