mariadb-install-db
Initialize the MariaDB data directory
TLDR
Initialize a database
Display help
SYNOPSIS
mariadb-install-db [options]
PARAMETERS
--basedir=path
Specifies the base installation directory where MariaDB is installed.
--datadir=path
Defines the path where the MariaDB data files, including system tables, will be stored. This is a mandatory option if the default location is not desired.
--defaults-file=path
Reads default options from the specified file. This must be the first option on the command line.
--defaults-extra-file=path
Reads extra default options from the specified file after the global defaults file.
--force
Proceeds with the installation even if the data directory already exists and is not empty. Use with caution as this can overwrite existing data.
--no-defaults
Prevents reading default options from any option files.
--random-password
Generates a random password for the 'root' user and prints it to standard output. This is highly recommended for security.
--rpm
Internal option used by RPM packages. It typically implies --force and other settings relevant for package installation.
--skip-test-db
Prevents the creation of the 'test' database during installation.
--user=user_name
Specifies the system user under which mariadb-install-db should run. This is crucial for correct file permissions; typically 'mysql' or the system's MariaDB user.
DESCRIPTION
The mariadb-install-db command is a crucial utility used to create the initial MariaDB data directory and populate it with the necessary system tables (e.S. user, db, host, tables_priv, columns_priv, procs_priv).
It's typically executed after installing MariaDB, but before starting the MariaDB server (mariadbd) for the very first time. This command sets up the foundational database structure, including the initial 'root' user account (which by default has no password, requiring immediate securing via mysql_secure_installation or by using the --random-password option).
mariadb-install-db does not start the database server; it only prepares the environment for it. It was formerly known as mysql_install_db in MySQL and earlier MariaDB versions.
CAVEATS
- Run Once: mariadb-install-db should only be run once per data directory. Running it multiple times on an already initialized directory (without --force) will result in an error.
- No Server Start: This command only prepares the data directory; it does not start the MariaDB server. You must start mariadbd separately after installation.
- Root Password: By default, the 'root' user is created without a password. It is critical to secure this account immediately after installation using mysql_secure_installation or by employing the --random-password option during initialization.
- Permissions: Ensure the command is run with appropriate permissions, typically as the 'mysql' system user or as root, to correctly set up file ownership and permissions for the data directory.
SECURITY BEST PRACTICES
After running mariadb-install-db, especially if you didn't use --random-password, it's paramount to immediately run the mysql_secure_installation script. This script guides you through setting a 'root' password, removing anonymous users, disallowing remote root logins, and removing the 'test' database, significantly enhancing the security of your MariaDB installation.
DATA DIRECTORY MANAGEMENT
The --datadir option is crucial for specifying the location of your MariaDB data. It's recommended to choose a dedicated partition or volume for the data directory to manage disk space and I/O performance effectively. Ensure the chosen directory is empty or used with caution if --force is applied.
HISTORY
Originally, this utility was known as mysql_install_db and was an integral part of MySQL distributions. When MariaDB forked from MySQL, it initially retained the mysql_install_db name for compatibility. Over time, for branding consistency and clarity, it was renamed to mariadb-install-db. Its fundamental purpose and functionality have remained consistent throughout its evolution: to initialize the database system tables and prepare the data directory for the server's first start.
SEE ALSO
mariadbd(8), mysql_secure_installation(1), mariadb(1), mysqld(8)