mysql_install_db

You are viewing an old version of this article. View the current version here.

mysql_install_db initializes the MariaDB data directory and creates the system tables in the mysql database, if they do not exist. MariaDB uses these tables to manage privileges, roles, and plugins. It also uses them to provide the data for the help command in the mysql client.

mysql_install_db works by starting MariaDB Server's mysqld process in --bootstrap mode and sending commands to create the system tables and their content.

There is a version specifically for Windows, mysql_install_db.exe.

Using mysqld_install_db

To invoke mysql_install_db, use the following syntax:

$ mysql_install_db [options]

Because the MariaDB server, mysqld, needs to access the data directory when it runs later, you should either run mysql_install_db from the same account that will be used for running mysqld or run it as root and use the --user option to indicate the user name that mysqld will run as. It might be necessary to specify other options such as --basedir or --datadir if mysql_install_db does not use the correct locations for the installation directory or data directory. For example:

$ scripts/mysql_install_db --user=mysql \
   --basedir=/opt/mysql/mysql \
   --datadir=/opt/mysql/mysql/data

Options

mysql_install_db supports the following options:

OptionDescription
--auth-root-authentication-method={normal | socket}If set to normal, it creates a root@localhost account that authenticates with the mysql_native_password authentication plugin and that has no initial password set, which can be insecure. If set to socket, it creates a root@localhost account that authenticates with the unix_socket authentication plugin. Set to normal by default. Available since MariaDB 10.1.
--auth-root-socket-user=USERUsed with --auth-root-authentication-method=socket. It specifies the name of the second account to create with SUPER privileges in addition to root, as well as of the system account allowed to access it. Defaults to the value of --user.
--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=path, --ldata=pathThe path to the MariaDB data directory.
--defaults-extra-file=nameRead this file after the global files are read. Must be given as the first option.
--defaults-file=nameOnly read default options from the given file name Must be given as the first option.
--defaults-group-suffix=nameIn addition to the given groups, read also groups with this suffix. From MariaDB 10.1.31, MariaDB 10.2.13 and MariaDB 10.3.5.
--forceCauses mysql_install_db to run even if DNS does not work. In that case, grant table entries that normally use host names will use IP addresses.
--no-defaultsDon't read default options from any option file. Must be given as the first option.
--print-defaultsPrint the program argument list and exit. Must be given as the first option.
--rpmFor internal use. This option is used by RPM files during the MariaDB installation process.
--skip-auth-anonymous-userDo not create the anonymous user.
--skip-name-resolveUses IP addresses rather than host names when creating grant table entries. This option can be useful if your DNS does not work.
--skip-test-dbDon't install the test database.
--srcdir=pathFor internal use. The 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. The directory under which mysql_install_db looks for support files such as the error message file and the file for populating the help tables.
--user=user_nameThe login user name 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.
--verboseVerbose mode. Print more information about what the program does.
--windowsFor internal use. This option is used for creating Windows distributions.

Option Files

In addition to reading options from the command-line, mysql_install_db can also read options from option files. If an unknown option is provided to mysql_install_db in an option file, then it is ignored.

The following options relate to how MariaDB command-line tools handles option files. They must be given as the first argument on the command-line:

OptionDescription
--print-defaultsPrint the program argument list and exit.
--no-defaultsDon't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# In addition to the default option groups, also read option groups with this suffix.

Option Groups

mysql_install_db reads options from the following option groups from option files:

GroupDescription
[mysql_install_db] Options read by mysqld_safe, which includes both MariaDB Server and MySQL Server.

mysql_install_db also reads options from the following server option groups from option files:

GroupDescription
[mysqld] Options read by mysqld, which includes both MariaDB Server and MySQL Server.
[server]Options read by MariaDB Server.
[mysqld-X.Y] Options read by a specific version of mysqld, which includes both MariaDB Server and MySQL Server. For example, [mysqld-5.5].
[mariadb]Options read by MariaDB Server.
[mariadb-X.Y] Options read by a specific version of MariaDB Server.
[client-server]Options read by all MariaDB client programs and the MariaDB Server. This is useful for options like socket and port, which is common between the server and the clients.
[galera] Options read by a galera-capable MariaDB Server. Available on systems compiled with Galera support.

Installing System Tables

Installing System Tables From a Source Tree

If you have just compiled MariaDB from source, and if you want to use mysql_install_db from your source tree, then that can be done without having to actually install MariaDB. This is very useful if you want to test your changes to MariaDB without disturbing any existing installations of MariaDB.

To do so, you would have to provide the --srcdir option. For example:

./scripts/mysql_install_db --srcdir=. --datadir=path-to-temporary-data-dir

Installing System Tables From a Binary Tarball

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

One possible solution is to use the --no-defaults option, so that it does not read any option files. For example:

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

Another possible solution is to use the defaults-file option, so that you can specify your own option file. For example:

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

Troubleshooting Issues

Checking the Error Log

If mysql_install_db fails, you should examine the error log in the data directory, which is the directory specified with --datadir option. This should provide a clue about what went wrong.

Testing With mysqld

You can also test that this is not a general fault of MariaDB Server by trying to start the mysqld process. The -skip-grant-tables option will tell it to ignore the system tables. Enabling the general query log can help you determine what queries are being run on the server. For example:

mysqld --skip-grant-tables --general-log

At this point, you can use the mysql client to connect to the mysql database and look at the system tables. For example:

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

Using a Server Compiled With --disable-grant-options

The following only apply in the exceptional case that you are using a mysqld server which is configured with the --disable-grant-options option:

mysql_install_db needs to invoke mysqld with the --bootstrap and --skip-grant-tables options. A MariaDB configured with the --disable-grant-options option has --bootstrap and --skip-grant-tables disabled. To handle this case, set the MYSQLD_BOOTSTRAP environment variable to the full path name of a mysqld server that is configured without --disable-grant-options. mysql_install_db will use that server.

See Also

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.