Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 31.4Mb
PDF (A4) - 31.5Mb
PDF (RPM) - 29.9Mb
HTML Download (TGZ) - 7.5Mb
HTML Download (Zip) - 7.5Mb
HTML Download (RPM) - 6.4Mb
Man Pages (TGZ) - 177.3Kb
Man Pages (Zip) - 287.6Kb
Info (Gzip) - 3.0Mb
Info (Zip) - 3.0Mb
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 and scripts subdirectories, which contain the server as well as the client and utility programs.

  2. 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> scripts/mysql_install_db --user=mysql

    It is important to make sure that the database directories and files are owned by the mysql login account so that the server has read and write access to them when you run it later. To ensure this if you run mysql_install_db as root, include the --user option as shown.

    The mysql_install_db command initializes the server's data directory. Under the data directory, it creates directories for the mysql database that holds the grant tables and the test database that you can use to test MySQL. The program also creates privilege table entries for the initial account or accounts. test_. For a complete listing and description of the grant tables, see Section 6.2, “The MySQL Access Privilege System”.

    It might be necessary to specify other options such as --basedir or --datadir if mysql_install_db cannot identify the correct locations for the installation directory or data directory. For example:

    shell> scripts/mysql_install_db --user=mysql \
             --basedir=/opt/mysql/mysql \

    For a more secure installation, invoke mysql_install_db with the --random-passwords option. This causes it to assign a random password to the MySQL root accounts, set the password expired flag for those accounts, and remove the anonymous-user MySQL accounts. For additional details, see Section 4.4.3, “mysql_install_db — Initialize MySQL Data Directory”. (Install operations using RPMs for Unbreakable Linux Network are unaffected because they do not use mysql_install_db.)

    If you do not want to have the test database, you can remove it after starting the server, using the instructions in Section 2.10.4, “Securing the Initial MySQL Accounts”.

    If you have trouble with mysql_install_db at this point, see Section, “Problems Running mysql_install_db”.

  3. To specify options that the MySQL server should use at startup, put them in a /etc/my.cnf or /etc/mysql/my.cnf file. See Section 5.1.2, “Server Configuration Defaults”. If you do not do this, the server starts with its default settings.

  4. 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.