4.4.2 mysql_install_db — Initialize MySQL Data Directory (original) (raw)

4.4.2 mysql_install_db — Initialize MySQL Data Directory

mysql_install_db handles initialization tasks that must be performed before the MySQL server,mysqld, is ready to use:

Secure-by-Default Deployment

Current versions of mysql_install_db produce a MySQL deployment that is secure by default, with these characteristics:

If mysql_install_db generates a random administative password, it writes the password to a file and displays the file name. The password entry includes a timestamp to indicate when it was written. By default, the file is.mysql_secret in the home directory of the effective user running the script..mysql_secret is created with mode 600 to be accessible only to the operating system user for whom it is created.

Important

When mysql_install_db generates a random password for the administrative account, it is necessary aftermysql_install_db has been run to start the server, connect using the administrative account with the password written to the .mysql_secret file, and specify a new administrative password. Until this is done, the administrative account cannot be used for anything else. To change the password, you can use theSET PASSWORD statement (for example, with the mysql ormysqladmin client). After resetting the password, remove the .mysql_secret file; otherwise, if you runmysql_secure_installation, that command may see the file and expire the root password again as part of ensuring secure deployment.

Invocation Syntax

Change location to the MySQL installation directory and use this invocation syntax:

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

The --datadir option is mandatory. mysql_install_db creates the data directory, which must not already exist:

Because the MySQL server, mysqld, must access the data directory when it runs later, you should either runmysql_install_db from the same system account used for running mysqld, or run it asroot and specify the--user option to indicate the user name that mysqld runs under. It might be necessary to specify other options such as--basedir ifmysql_install_db does not use the correct location for the installation directory. For example:

bin/mysql_install_db --user=mysql \
    --basedir=/opt/mysql/mysql \
    --datadir=/opt/mysql/mysql/data

Note

If you have set a custom TMPDIR environment variable when performing the installation, and the specified directory is not accessible,mysql_install_db may fail. If so, unsetTMPDIR or set TMPDIR to point to the system temporary directory (usually/tmp).

Administrative Account Creation

mysql_install_db creates an administrative account named 'root'@'localhost' by default.

mysql_install_db provides options that enable you to control several aspects of the administrative account:

For more information, see the descriptions of those options.

mysql_install_db assignsmysql.user system table rows a nonemptyplugin column value to set the authentication plugin. The default value ismysql_native_password. The value can be changed using the--admin-auth-plugin option.

Default my.cnf File

mysql_install_db creates no defaultmy.cnf file.

Note

As of MySQL 5.7.18, my-default.cnf is no longer included in or installed by distribution packages.

With one exception, the settings in the default option file are commented and have no effect. The exception is that the file sets the sql_mode system variable toNO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES. This setting produces a server configuration that results in errors rather than warnings for bad data in operations that modify transactional tables. See Section 5.1.10, “Server SQL Modes”.

Command Options

mysql_install_db supports the following options, which can be specified on the command line or in the[mysql_install_db] group of an option file. For information about option files used by MySQL programs, seeSection 4.2.2.2, “Using Option Files”.