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
. Windows version shares the common theme (creating system tables), yes has a lot functionality are specific to Windows systems , for example creating Windows service. Windows version does *not* share parameters with the Unix shell script, and if you are looking for Windows specific instruction, refer to mysql_install_db.exe
instead of reading this page.
From MariaDB 10.4.6, mariadb-install-db
is a symlink to mysql_install_db
.
From MariaDB 10.5.2, mysqld_install_db
is the symlink, and mariadb-install-db
the binary name.
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 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 socket by default from MariaDB 10.4 (see Authentication from MariaDB 10.4), or normal by default in earlier versions. Available since MariaDB 10.1. |
--auth-root-socket-user=USER | Used 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=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
User Accounts Created by Default
MariaDB starting with 10.4
In MariaDB 10.4 and later, mysql_install_db
sets --auth-root-authentication-method=socket
by default. When this is set, the default root@localhost
user account is created with the ability to use two authentication plugins:
- First, it is configured to try to use the
unix_socket
authentication plugin. This allows the theroot@localhost
user to login without a password via the local Unix socket file defined by thesocket
system variable, as long as the login is attempted from a process owned by the operating systemroot
user account. - Second, if authentication fails with the
unix_socket
authentication plugin, then it is configured to try to use themysql_native_password
authentication plugin.
The definition of the default root@localhost
user account is:
CREATE USER 'root'@'localhost' IDENTIFIED VIA unix_socket OR mysql_native_password USING 'invalid'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION;
Since mysql_install_db
sets --auth-root-authentication-method=socket
by default, the following additional user accounts are not created by default:
[email protected]
root@::1
root@${current_hostname}
However, an additional user account that is defined by the --auth-root-socket-user
option is created. If this option is not set, then the value defaults to the value of the --user
option. On most systems, the --user
option will use the value of mysql
by default, so this additional user account would be called mysql@localhost
.
The definition of this mysql@localhost
user account is similar to the root@localhost
user account:
CREATE USER 'mysql'@'localhost' IDENTIFIED VIA unix_socket OR mysql_native_password USING 'invalid'; GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' WITH GRANT OPTION;
An invalid password is initially set for both of these user accounts. This means that before a password can be used to authenticate as either of these user accounts, the accounts must first be given a valid password by executing the SET PASSWORD
statement.
For example, here is an example of setting the password for the root@localhost
user account immediately after installation:
$ sudo yum install MariaDB-server $ sudo systemctl start mariadb $ sudo mysql ... MariaDB> SET PASSWORD = PASSWORD('XH4VmT3_jt');
You may notice in the above example that the mysql
command-line client is executed via sudo
. This allows the root@localhost
user account to successfully authenticate via the unix_socket
authentication plugin.
MariaDB until 10.3
In MariaDB 10.3 and before, mysql_install_db
sets --auth-root-authentication-method=normal
by default. When this is set, the following default accounts are created with no password:
root@localhost
[email protected]
root@::1
root@${current_hostname}
The definition of the default root@localhost
user account is:
CREATE USER 'root'@'localhost'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION; GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION;
The definition of the other default root
accounts is similar.
A password should be set for these user accounts immediately after installation. This can be done either by executing the SET PASSWORD
statement or by running mysql_secure_installation
.
For example, here is an example of setting the password for the root@localhost
user account immediately after installation:
$ sudo yum install MariaDB-server $ sudo systemctl start mariadb $ mysql -u root ... MariaDB> SET PASSWORD = PASSWORD('XH4VmT3_jt');
Since mysql_install_db
sets --auth-root-authentication-method=normal
by default, the --auth-root-socket-user
option is ignored by default.
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