mariadb
Access and manage MariaDB databases
TLDR
Connect to a specific MariaDB database
Connect to a specific MariaDB database using username and password
Show warnings after every statement in interactive and batch mode
Display less verbose outputs (can be used multiple times to produce less output)
Execute SQL statements from a script file
Check memory and open file usage at exit
Connect using a socket file for local connections
Display help
SYNOPSIS
mariadb [options] [database]
PARAMETERS
-u, --user=user_name
Specifies the MariaDB user name for connection.
-p, --password[=password]
Specifies the MariaDB password. If password is not given it asks for one.
-h, --host=host_name
Specifies the host to connect to.
-P, --port=port_number
Specifies the port number to use for the connection.
-D, --database=db_name
Database to use.
-e, --execute=statement
Execute command and quit.
-s, --silent
Be more silent. Print results with a tab as separator, each row on new line.
-v, --verbose
Verbose mode. Print more information about what the program does.
--version
Display version information and exit.
DESCRIPTION
The `mariadb` command is a versatile client for interacting with MariaDB database servers.
It allows users to connect to a MariaDB server, execute SQL statements, and manage database operations from the command line. It's a powerful tool for database administrators, developers, and anyone needing to directly interact with MariaDB.
This tool provides an interactive interface to query, update, and administer the MariaDB server. It reads commands from standard input (or from files specified as arguments) and executes them. It supports various connection options, allowing you to specify the host, user, password, and database to connect to. The `mariadb` command is essential for tasks such as creating databases and tables, inserting and updating data, running complex queries, and managing user privileges. Its interactive mode makes it useful for quick tests and administration, while its ability to execute commands from files allows for automated tasks and scripting.
CAVEATS
The `-p` option without an argument prompts for a password, but leaving it blank on the command line can expose the password in shell history. Storing passwords directly in scripts is highly discouraged for security reasons. Consider using configuration files or environment variables instead.
CONFIGURATION FILES
The `mariadb` command can read connection options from configuration files such as `~/.my.cnf` or `/etc/my.cnf`. This allows you to store connection details securely and reuse them across multiple invocations of the command. The order of precedence for options is command-line arguments override environment variables and configuration files.
Example Configuration (~/.my.cnf):
[client]
user=your_user
password=your_password
host=your_host
BATCH MODE
The `-e` option allows you to execute SQL statements in non-interactive or batch mode. This is useful for running scripts or automating database tasks. Multiple statements can be separated by semicolons (`;`).
Example: mariadb -u user -p -e "SELECT * FROM table1; SHOW TABLES;"
HISTORY
The `mariadb` command evolved from the `mysql` client after the MariaDB fork from MySQL. It aims to provide a compatible but independent client for interacting with MariaDB servers. The development focuses on maintaining compatibility while introducing new features and improvements specific to the MariaDB ecosystem.
Originally, the `mysql` command served both MySQL and MariaDB servers. Due to diverging development paths and licensing concerns, MariaDB created a separate `mariadb` command to ensure independent evolution and control.