MySQL Installation Guide  /  Postinstallation Setup and Testing  /  Initializing the Data Directory

9.1 Initializing the Data Directory

After installing MySQL, the data directory must be initialized, including the tables in the mysql system database:

  • For some MySQL installation methods, data directory initialization is automatic, as described in Chapter 9, Postinstallation Setup and Testing.

  • For other installation methods, you must initialize the data directory manually. These include installation from generic binary and source distributions on Unix and Unix-like system, and installation from a ZIP Archive package on Windows.

This section describes how to initialize the data directory manually. For some suggested commands that enable testing whether the server is accessible and working properly, see Section 9.3, “Testing the Server”.

In the examples shown here, the server is intended 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 Create a mysql User and Group, in Chapter 3, Installing MySQL on Unix/Linux Using Generic Binaries.

  1. Change location to the top-level directory of your MySQL installation directory, which is typically /usr/local/mysql (adjust the path name for your system as necessary):

    cd /usr/local/mysql

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

  2. The secure_file_priv system variable limits import and export operations to a specific directory. Create a directory whose location can be specified as the secure_file_priv value:

    mkdir mysql-files

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

    chown mysql:mysql mysql-files
    chmod 750 mysql-files
  3. Use the server to 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. For example:

    bin/mysqld --initialize --user=mysql

    For some important information on the command, especially on the command options you might use, see Section 9.1.1, “Initializing the Data Directory Manually”.

    Typically, data directory initialization need be done only after you first install MySQL. (For upgrades to an existing installation, perform the upgrade procedure instead; see Chapter 10, Upgrading MySQL.) However, the command that initializes the data directory does not overwrite any existing privilege tables, so it is safe to run in any circumstances. Use the server to initialize the data directory; for example:


    Initialization of the data directory might fail if required system libraries are missing. For example, you might see an error like this:

    bin/mysqld: error while loading shared libraries: cannot
    open shared object file: No such file or directory

    If this happens, you must install the missing libraries manually or with your system's package manager. Then retry the data directory initialization command.

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


    For more information, see 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, as mentioned earlier in this procedure, by setting the secure_file_priv system variable at server startup to a directory where SELECT writes can be performed safely.

  6. In the absence of any option files, the server starts with its default settings. (See Server Configuration Defaults.) To specify options that the MySQL server should use at startup, put them in an option file such as /etc/my.cnf or /etc/mysql/my.cnf. (See Using Option Files.) For example, you can use an option file to set the secure_file_priv system variable.

  7. To arrange for MySQL to start without manual intervention at system boot time, see Section 9.5, “Starting and Stopping MySQL Automatically”.

  8. Data directory initialization creates time zone tables in the mysql database but does not populate them. To do so, use the instructions in 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.