Documentation Home
MySQL 5.7 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 39.4Mb
PDF (A4) - 39.4Mb
PDF (RPM) - 38.7Mb
HTML Download (TGZ) - 11.1Mb
HTML Download (Zip) - 11.1Mb
HTML Download (RPM) - 9.8Mb
Man Pages (TGZ) - 214.1Kb
Man Pages (Zip) - 323.3Kb
Info (Gzip) - 3.6Mb
Info (Zip) - 3.6Mb
Excerpts from this Manual

2.10.1 Initializing the Data Directory

After installing MySQL, the data directory, including the tables in the mysql system database, must be initialized. For some MySQL installation methods, data directory initialization can be done automatically, as described in Section 2.10, “Postinstallation Setup and Testing”. For other installation methods, including installation from generic binary and source distributions, you must initialize the data directory yourself.

This section describes how to initialize the data directory on Unix and Unix-like systems. (For Windows, see Section 2.3.7, “Windows Postinstallation Procedures”.) For some suggested commands that you can use to test whether the server is accessible and working properly, see Section 2.10.3, “Testing the Server”.

In the examples shown here, the server is going to run under the user ID of the mysql login account. This assumes that such an account exists. Either create the account if it does not exist, or substitute the name of a different existing login account that you plan to use for running the server. For information about creating the account, see Creating a mysql System User and Group, in Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”.

  1. Change location into the top-level directory of your MySQL installation directory, which is typically /usr/local/mysql:

    shell> cd /usr/local/mysql

    You will find several files and subdirectories inside the folder, including the bin subdirectory, which contains the server as well as the client and utility programs.

  2. Create a directory whose location can be provided to the secure_file_priv system variable, which limits import/export operations to that specific directory:

    shell> mkdir mysql-files

    Grant ownership of the directory to the mysql user and group ownership to the mysql group, and set the right permissions for the directory:

    shell> chown mysql:mysql mysql-files
    shell> chmod 750 mysql-files
  3. Initialize the data directory, including the mysql database containing the initial MySQL grant tables that determine how users are permitted to connect to the server.

    Typically, data directory initialization need be done only after you first installed MySQL. (If you are upgrading an existing installation, you should perform the upgrade procedure instead; see Section 2.11, “Upgrading MySQL”.) However, the command that initializes the data directory does not overwrite any existing privilege tables, so it should be safe to run in any circumstances. Use the server to initialize the data directory; for example:

    shell> bin/mysqld --initialize --user=mysql

    See Section, “Initializing the Data Directory Manually Using mysqld” for some important information on the command, especially on the command options you might use.


    Initialization of the data directory might fail because some required software libraries are missing from your system. For example:

    shell> bin/mysqld --initialize --user=mysql
    bin/mysqld: error while loading shared libraries: cannot
    open shared object file: No such file or directory

    When this happens, you have to install the missing libraries manually or with your system's package manager before retrying the data directory initialization.

  4. If you want the server to be able to deploy with automatic support for secure connections, use the mysql_ssl_rsa_setup utility to create default SSL and RSA files:

    shell> bin/mysql_ssl_rsa_setup

    For more information, see Section 4.4.5, “mysql_ssl_rsa_setup — Create SSL/RSA Files”.

  5. If the plugin directory (the directory named by the plugin_dir system variable) is writable by the server, it may be possible for a user to write executable code to a file in the directory using SELECT ... INTO DUMPFILE. This can be prevented by making the plugin directory read only to the server or by setting the secure_file_priv system variable at server startup to a directory where SELECT writes can be performed safely. (For example, set it to the mysql-files directory created earlier.)

  6. To specify options that the MySQL server should use at startup, put them in a /etc/my.cnf or /etc/mysql/my.cnf file. You can use such a file to set, for example, the secure_file_priv system variable. See Section 5.1.2, “Server Configuration Defaults”. If you do not do this, the server starts with its default settings.

  7. If you want MySQL to start automatically when you boot your machine, see Section 2.10.5, “Starting and Stopping MySQL Automatically”.

Data directory initialization creates time zone tables in the mysql database but does not populate them. To do so, use the instructions in Section 5.1.12, “MySQL Server Time Zone Support”.

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.