This page is for the mariadb-install-db script for Linux/Unix only.
For the Windows specific tool of similar name and purpose see mysql_install_db.exe.
The Windows version shares the common theme (creating system tables), yet has a lot of functionality specific to Windows systems, for example creating a Windows service. The Windows version does not share command line parameters with the Unix shell script.
mariadb-install-db initializes the MariaDB data directory and creates the in the database, if they do not exist.
MariaDB uses these tables to manage , , and . It also uses them to provide the data for the command in the client.
mariadb-install-db works by starting MariaDB Server's mariadbd process in mode and sending commands to create the and their content.
Invoke mariadb-install-db using the following syntax:
Because the MariaDB server (mariadbd) needs to access the data directory when it runs, you should either run mariadb-install-db from the same account that is used for running mariadbd, or run it as root and use the --user option to indicate the username that mariadbd runs as. It might be necessary to specify other options such as --basedir or --datadir if mariadb-install-db does not use the correct locations for the installation directory or data directory. Here is a typical invocation:
mariadb-install-db supports the following options:
normal|socket}If set to normal, it creates a root@localhost account that authenticates with the 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 authentication plugin. Set to socket by default.
Used with --auth-root-authentication-method=socket. It specifies the name of the second account to create with privileges in addition to root, as well as of the system account allowed to access it. Defaults to the value of --user.
The path to the MariaDB installation directory.
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.
Initialize MariaDB for . Argument is a list of the catalogs to create, separated with space or comma. The def catalog is created automatically. This option is available from MariaDB 11.7.
User when adding catalogs to running server. This option is available from MariaDB 11.7.
Password for . This option is available from MariaDB 11.7.
Other arguments to mariadb when adding new . This option is available from MariaDB 11.7.
For internal use. Used when building the MariaDB system tables on a different host than the target.
The path to the MariaDB data directory.
Write commands to-be executed in /tmp/mariadb_install_db.log. This option is available from MariaDB 11.6.
Start mariadbd (server) with --debug.
Read this file after the global files are read. Must be given as the first option.
Only read default options from the given file name. Must be given as the first option.
In addition to the given groups, read also groups with this suffix.
Causes mariadb-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.
Don't read default options from any option file. Must be given as the first option.
Print the program argument list and exit. Must be given as the first option.
For internal use. This option is used by RPM files during the MariaDB installation process.
Uses IP addresses rather than host names when creating grant table entries. This option can be useful if your DNS does not work.
Don't install the test database.
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 mariadb-install-db looks for support files such as the error message file and the file for populating the help tables.
The login username to use for running mariadbd. Files and directories created by mariadbd is owned by this user. You must be root to use this option. By default, mariadbd runs using your current login name and files and directories that it creates is owned by you.
Verbose mode. Print more information about what the program does.
For internal use. This option is used for creating Windows distributions.
In addition to reading options from the command line, mariadb-install-db can also read options from . If an unknown option is provided to mariadb-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:
mariadb-install-db reads options from the following from :
mariadb-install-db also reads options from the following server from :
If you have just , and if you want to use mariadb-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:
If you install a 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 . For example:
Another possible solution is to use the defaults-file option, so that you can specify your own . For example:
mariadb-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 :
First, it is configured to try to use the authentication plugin. This allows the root@localhost user to login without a password via the local Unix socket file defined by the system variable, as long as the login is attempted from a process owned by the operating system root user account.
Second, if authentication fails with the authentication plugin, then it is configured to try to use the authentication plugin.
The definition of the default root@localhost user account is:
Since mariadb-install-db sets --auth-root-authentication-method=socket by default, the following additional user accounts are not created by default:
root@127.0.0.1
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:
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 statement.
For example, here is an example of setting the password for the root@localhost user account immediately after installation:
You may notice in the above example that the command-line client is executed via . This allows the root@localhost user account to successfully authenticate via the authentication plugin.
If mariadb-install-db fails, you should examine the in the data directory, which is the directory specified with --datadir option. This should provide a clue about what went wrong.
You can also test that this is not a general fault of MariaDB Server by trying to start the mariadbd process. The option will tell it to ignore the . Enabling the can help you determine what queries are being run on the server. For example:
At this point, you can use the client to connect to the database and look at the . For example:
The following only apply in the exceptional case that you are using a mariadbd server which is configured with the --disable-grant-options option:
mariadb-install-db needs to invoke mariadbd 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 mariadbd server that is configured without --disable-grant-options. mariadb-install-db will use that server.
When calling the mariadb-install-db script, a new folder called test is created in the data directory.
It only has the single db.opt file, which sets the client options default-character-set and default-collation only.
If you run mysql as an anonymous user, mysql -u''@localhost, and look for the grants and databases you are able to work with, you will get the following:
Shown are the information_schema as well as test databases that are built in databases.
But looking from appears to be a paradox; how can the current user see something if they don't have privileges for that?
Let's go a step further.
Now, use the root/unix user, which has all rights, in order to create a new database with the prefix test_ , something like:
With the above change, a new directory is created in the data directory. Now login again with the anonymous user and run :
Again we are able to see the newly created database, without any rights?
We have an anonymous user that has no privileges, but still can see the test and test_electricity databases. Where does this come from?
Log in with the root/unix user to find out all privileges that the anonymous user has:
As seen above from the table, the anonymous user doesn't have any global privileges.
Still, the anonymous user can see databases, so there must be a way so that anonymous user can see the test and test_electricity databases.
Let's check for grants on the database level. That information can be found in the table.
Looking at the mysql.db table, it already contains 2 rows created when the mariadb-install-db script was invoked.
The anonymous user has database privileges (without grant, alter_routine and execute) on test and test_% databases:
The first row is reserved for explicit usage for the test database, which is automatically created with mariadb-install-db.
Since database test_electricity satisfies the test_% pattern where test_ is a prefix, we can understand why the user has the right to work with the newly-created database.
As long as records in mysql.db for the anonymous user exists, each new user created will have the privileges for the test and test_% databases.
Other databases privileges are not automatically granted for the newly created user. We have to grant privileges, which is visible in mysql.db table.
If you run mariadb-install-db with the --skip-test-db option, no test database is created, which we can see as follows:
Also, no anonymous user is created (only unix/mariadb.sys/root users):
The Windows version of mariadb-install-db:
This page is licensed: CC BY-SA / Gnu FDL
[galera]
Options read by a galera-capable MariaDB Server. Available on systems compiled with Galera support.
--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.
[mysql_install_db]
Options read by mysqld_safe, which includes both MariaDB Server and MySQL Server.
[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.
$ mariadb-install-db [options]$ scripts/mariadb-install-db --user=mysql \
--basedir=/opt/mysql/mysql \
--datadir=/opt/mysql/mysql/data./scripts/mariadb-install-db --srcdir=. --datadir=path-to-temporary-data-dir./scripts/mariadb-install-db --no-defaults --basedir=. --datadir=data./scripts/mariadb-install-db --defaults-file=~/.my.cnfCREATE 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;CREATE USER 'mysql'@'localhost' IDENTIFIED VIA unix_socket
OR mysql_native_password USING 'invalid';
GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'localhost' WITH GRANT OPTION;$ sudo yum install MariaDB-server
$ sudo systemctl start mariadb
$ sudo mariadb
...
MariaDB> SET PASSWORD = PASSWORD('XH4VmT3_jt');mariadbd --skip-grant-tables --general-log$ /usr/local/mysql/bin/mysql -u root mysql
MariaDB [mysql]> show tablesSELECT current_user;
+--------------+
| current_user |
+--------------+
| @localhost |
+--------------+
SHOW GRANTS FOR current_user;
+--------------------------------------+
| Grants for @localhost |
+--------------------------------------+
| GRANT USAGE ON *.* TO ``@`localhost` |
+--------------------------------------+
SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+CREATE DATABASE test_electricity;SHOW DATABASES
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| test_electricity |
+--------------------+SELECT * FROM mysql.user WHERE user='' AND host='localhost'\G
*************************** 1. row ***************************
Host: localhost
User:
Password:
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
Delete_history_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string:
password_expired: N
is_role: N
default_role:
max_statement_time: 0.000000SELECT * FROM mysql.db\G
*************************** 1. row ***************************
Host: %
Db: test
User:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Grant_priv: N
References_priv: Y
Index_priv: Y
Alter_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: N
Execute_priv: N
Event_priv: Y
Trigger_priv: Y
Delete_history_priv: Y
*************************** 2. row ***************************
Host: %
Db: test\_%
User:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Grant_priv: N
References_priv: Y
Index_priv: Y
Alter_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: N
Execute_priv: N
Event_priv: Y
Trigger_priv: Y
Delete_history_priv: YSHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
SELECT * FROM mysql.db;
Empty set (0.001 sec)SELECT user,host FROM mysql.user;
+-------------+-----------+
| User | Host |
+-------------+-----------+
| anel | localhost |
| mariadb.sys | localhost |
| root | localhost |
+-------------+-----------+