mysql_install_db
Contents
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:
Option | Description |
---|---|
--auth-root-authentication-method={normal | If set to normal , it creates a root@localhost account that authenticates with the mysql_native_password authentication plugin, which has no initial password set. 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=USER | The name of the user to create that will have SUPER privileges and that will that authenticate with the unix_socket authentication plugin. Defaults to root . Available since MariaDB 10.1. |
--basedir=path | The path to the MariaDB installation directory. |
--builddir=path | If 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-bootstrap | For internal use. Used when building the MariaDB system tables on a different host than the target. |
--datadir=path , --ldata=path | The path to the MariaDB data directory. |
--defaults-extra-file=name | Read this file after the global files are read. Must be given as the first option. |
--defaults-file=name | Only read default options from the given file name Must be given as the first option. |
--defaults-group-suffix=name | In 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. |
--force | Causes 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-defaults | Don't read default options from any option file. Must be given as the first option. |
--print-defaults | Print the program argument list and exit. Must be given as the first option. |
--rpm | For internal use. This option is used by RPM files during the MariaDB installation process. |
--skip-auth-anonymous-user | Do not create the anonymous user. |
--skip-name-resolve | Uses IP addresses rather than host names when creating grant table entries. This option can be useful if your DNS does not work. |
--skip-test-db | Don't install the test database. |
--srcdir=path | For 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_name | The 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. |
--verbose | Verbose mode. Print more information about what the program does. |
--windows | For 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:
Option | Description |
---|---|
--print-defaults | Print the program argument list and exit. |
--no-defaults | Don'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:
Group | Description |
---|---|
[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:
Group | Description |
---|---|
[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
- Installing system tables (mysql_install_db)
- The Windows version of
mysql_install_db
:mysql_install_db.exe