mysql_install_db - Initialize MySQL Data Directory


The mysql_install_db handles the initialization tasks which need to be performed before the MySQL server i.e mysqld is ready to use. It initializes the MySQL data directory and helps create the system tables that it contains. It initializes the system tablespace and the related data structures that are reuqired to manage the InnoDB tables.

Secure-by-Default Deployment

The current versions of mysql_install_db would produce a MySQL deployment which is secure by default. It has the below mentioned characteristics.

  • A single administrative account named 'root'@'localhost' is created with a randomly generated password and is marked as expired.

  • No anonymous user accounts are created.

  • No test database which is accessible by all users is created.

  • The ‘--admin-xxx’ options are available that help control the characteristics of the administrative account.

  • The ‘--random-password-file’ option is available to be controlled where the random password is written.

  • The ‘—insecure’ option is available to suppress the random password generation.

If mysql_install_db can generate a random administative password, it will write the password to a file and also display the file name.

Invocation syntax

Let us understand the invocation syntax now −

Change location to the MySQL installation directory and use the below mentioned syntax −

shell> bin/mysql_install_db --datadir=path/to/datadir [other_options]

The --datadir option is compulsory. The mysql_install_db creates the data directory, which shouldn’t exist already. If the data directory already exists, an upgrade operation is being performed, not an install operation. It should run mysql_upgrade and not mysql_install_db. If the data directory doesn’t exist but the mysql_install_db fails, any partially created data directory should be removed before running mysql_install_db again.

Because the MySQL server, mysqld must access the data directory when it runs later, the user should either run mysql_install_db from the same system account used for running mysqld, or run it as root and specify the --user option to indicate the user name which mysqld runs under.

Updated on: 10-Mar-2021

671 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements