The purpose of the mysql_install_db program
is to initialize the data directory, including the tables in the
mysql system database. It does not overwrite
existing MySQL privilege tables, and it does not affect any
To re-create your privilege tables, first stop the
mysqld server if it is running. Then rename
mysql directory under the data
directory to save it, and run
mysql_install_db. Suppose that your current
directory is the MySQL installation directory and that
mysql_install_db is located in the
bin directory and the data directory is
data. To rename the
mysql database and re-run
mysql_install_db, use these commands.
mv data/mysql data/mysql.oldshell>
When you run mysql_install_db, you might encounter the following problems:
mysql_install_db fails to install the grant tables
You may find that mysql_install_db fails to install the grant tables and terminates after displaying the following messages:
Starting mysqld daemon with databases from XXXXXX mysqld ended
In this case, you should examine the error log file very carefully. The log should be located in the directory
XXXXXXnamed by the error message and should indicate why mysqld did not start. If you do not understand what happened, include the log when you post a bug report. See How to Report Bugs or Problems.
There is a mysqld process running
This indicates that the server is running, in which case the grant tables have probably been created already. If so, there is no need to run mysql_install_db at all because it needs to be run only once, when you first install MySQL.
Installing a second mysqld server does not work when one server is running
This can happen when you have an existing MySQL installation, but want to put a new installation in a different location. For example, you might have a production installation, but you want to create a second installation for testing purposes. Generally the problem that occurs when you try to run a second server is that it tries to use a network interface that is in use by the first server. In this case, you should see one of the following error messages:
Can't start server: Bind on TCP/IP port: Address already in use Can't start server: Bind on unix socket...
For instructions on setting up multiple servers, see Running Multiple MySQL Instances on One Machine.
If you do not have write access to create temporary files or a Unix socket file in the default location (the
/tmpdirectory) or the
TMPDIRenvironment variable, if it has been set, an error occurs when you run mysql_install_db or the mysqld server.
You can specify different locations for the temporary directory and Unix socket file by executing these commands prior to starting mysql_install_db or mysqld, where
some_tmp_diris the full path name to some directory for which you have write permission:
export TMPDIR MYSQL_UNIX_PORT
Then you should be able to run mysql_install_db and start the server with these commands:
bin/mysqld_safe --user=mysql &
There are some alternatives to running the mysql_install_db program provided in the MySQL distribution:
If you want the initial privileges to be different from the standard defaults, use account-management statements such as
REVOKEto change the privileges after the grant tables have been set up. In other words, run mysql_install_db, and then use
mysql -u root mysqlto connect to the server as the MySQL
rootuser so that you can issue the necessary statements. (See Account Management Statements.)
To install MySQL on several machines with the same privileges, put the
REVOKEstatements in a file and execute the file as a script using
mysqlafter running mysql_install_db. For example:
bin/mysql -u root < your_script_file
This enables you to avoid issuing the statements manually on each machine.
It is possible to re-create the grant tables completely after they have previously been created. You might want to do this if you are just learning how to use
REVOKEand have made so many modifications after running mysql_install_db that you want to wipe out the tables and start over.
To re-create the grant tables, stop the server if it is running and remove the
mysqldatabase directory. Then run mysql_install_db again.