After installing MySQL, the data directory must be initialized,
including the tables in the
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.
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):
You will find several files and subdirectories inside the directory, including the
binsubdirectory, which contains the server as well as client and utility programs.
Grant user and group ownership of the directory to the
mysqlgroup, and set the appropriate permissions for the directory:
chown mysql:mysql mysql-files chmod 750 mysql-files
Use the server to initialize the data directory, including the
mysqldatabase 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:Note
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: libnuma.so.1: 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.
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.
If the plugin directory (the directory named by the
plugin_dirsystem 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_privsystem variable at server startup to a directory where
SELECTwrites can be performed safely.
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/mysql/my.cnf. (See Using Option Files.) For example, you can use an option file to set the
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
mysqldatabase but does not populate them. To do so, use the instructions in MySQL Server Time Zone Support.