After installing MySQL, the data directory, including the tables
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
mysql System User and Group, in
Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”.
Change location into the top-level directory of your MySQL installation directory, which is typically
shell> cd /usr/local/mysql
You will find several files and subdirectories inside the folder, including the
binsubdirectory, which contains the server as well as the client and utility programs.
Create a directory whose location can be provided to the
secure_file_privsystem variable, which limits import/export operations to that specific directory:
shell> mkdir mysql-files
Grant ownership of the directory to the
mysqluser and group ownership to the
mysqlgroup, and set the right permissions for the directory:
shell> chown mysql:mysql mysql-files shell> chmod 750 mysql-files
Initialize the data directory, including the
mysqldatabase 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 run mysql_upgrade instead (see Section 4.4.7, “mysql_upgrade — Check and Upgrade MySQL Tables”). 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 188.8.131.52, “Initializing the Data Directory Manually Using mysqld” for some important information on the command, especially on the command options you might use.Note
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: libnuma.so.1: 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.
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:
For more information, see Section 4.4.5, “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 by setting the
secure_file_privsystem variable at server startup to a directory where
SELECTwrites can be performed safely. (For example, set it to the
mysql-filesdirectory created earlier.)
To specify options that the MySQL server should use at startup, put them in a
/etc/mysql/my.cnffile. You can use such a file to set, for example, the
secure_file_privsystem variable. See Section 5.1.2, “Server Configuration Defaults”. If you do not do this, the server starts with its default settings.
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 10.6, “MySQL Server Time Zone Support”.