mysql_install_db is needed to create the system tables in the 'mysql' database directory. MariaDB uses these tables to manage user rights and provide the data for the 'help' command in the mysql client.

The normal usage of it is:

mysql_install_db --user=mysql

Here is a list of the options mysql_install_db supports:

--basedir=pathThe path to the MariaDB installation directory.
--builddir=pathIf using '--srcdir' with out-of-directory builds, you will need to set this to the location of the build directory where built files reside.
--cross-bootstrapFor internal use. Used when building the MariaDB system tables on a different host than the target.
--datadir=pathThe path to the MariaDB data directory.
--forceCauses mysql_install_db to run even if DNS does not work. In that case, grant table entries that normally use hostnames will use IP addresses.
--ldata=pathThe path to the MariaDB data directory. Same as '--datadir'.
--no-defaultsDon't read any configuration files (my.cnf).
--defaults-file=pathRead only this configuration file.
--rpmFor internal use. This option is used by RPM files during the MariaDB installation process.
--skip-name-resolveUse IP addresses rather than hostnames when creating grant table entries. This option can be useful if your DNS does not work.
--srcdir=pathThe path to the MariaDB source directory. This option uses the compiled binaries and support files within the source tree, useful for if you don't want to install MariaDB yet and just want to create the system tables.
--user=user_nameThe login username to use for running mysqld. Files and directories created by mysqld will be owned by this user. You must be root to use this option. By default mysqld runs using your current login name and files and directories that it creates will be owned by you.

mysql_install_db reads the my.cnf groups [mysqld] and [mysql_install_db]. In MariaDB 5.2 (and later), mysql_install_db also reads the my.cnf groups [mariadb] and [client-server].

mysql_install_db works by starting the mysqld server in --bootstrap mode and sending commands to create the system tables and their content.

If mysql_install_db fails, you should examine the logs (*.err files) in the data directory (the one specified with --datadir) for a clue of what went wrong.

You can also test that this is not a general fault of mysqld by starting mysqld with

mysqld --skip-grant --general-log

and use the mysql command line client tool (often located at /usr/local/mysql/bin/mysql for tarball installations of MariaDB) to connect to the mysql database and look at the grant tables:

shell> /usr/local/mysql/bin/mysql -u root mysql
MariaDB [mysql]> show tables

Installing a binary tar distribution:

If you install a tar file in a non standard path, like your home directory, and you already have a MariaDB / MySQL package installed, you may get conflicts with the default my.cnf file under /etc/. This often results in permissions errors.

The solution for this is to either execute the following command from the installation directory:

./scripts/mysql_install_db --no-defaults --basedir=. --datadir=data

or to specify your own config file (with the appropriate locations specified within it):

./scripts/mysql_install_db --defaults-file=~/.my.cnf

See also:

Comments

Comments loading...