After MySQL is installed, 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 systems, and installation from a ZIP Archive package on Windows.
This section describes how to initialize the data directory manually for MySQL installation methods for which data directory initialization is not automatic. 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 (see
Create a mysql User and Group), or
substitute the name of a different existing login account that you
plan to use for running the server.
Change location to the top-level directory of your MySQL installation, which is typically
/usr/local/mysql
(adjust the path name for your system as necessary):cd /usr/local/mysql
You can find several files and subdirectories inside the directory, including the
bin
andscripts
subdirectories, which contain the server as well as client and utility programs.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:scripts/mysql_install_db --user=mysql
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.
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 asroot
, 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 thetest
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 Access Control and Account Management.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 (enter the command on a single line):scripts/mysql_install_db --user=mysql --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql/data
For a more secure installation, invoke mysql_install_db with the
--random-passwords
option. This causes it to assign a random password to the MySQLroot
accounts, set the “password expired” flag for those accounts, and remove the anonymous-user MySQL accounts. For additional details, see 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 9.4, “Securing the Initial MySQL Accounts”.If you have trouble with mysql_install_db at this point, see Section 9.1.1, “Problems Running mysql_install_db”.
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 thesecure_file_priv
system variable.To arrange for MySQL to start without manual intervention at system boot time, see Section 9.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 MySQL Server Time Zone Support.