The purpose of the mysql_install_db script is to generate new MySQL privilege tables. It does not overwrite existing MySQL privilege tables, and it does not affect any other data.
If you want 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 then 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
XXXXXX named 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 Section 1.7, “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 install MySQL the first time).
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 Section 5.3, “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
/tmp directory) or the
TMP_DIR environment variable, if it has
been set, an error occurs when you run
mysql_install_db or the
You can specify different locations for the temporary
directory and Unix socket file by executing these commands
prior to starting mysql_install_db or
some_tmp_dir is 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 &
If mysql_install_db is located in the
scripts directory, modify the first
There are some alternatives to running the mysql_install_db script provided in the MySQL distribution:
If you want the initial privileges to be different from the
standard defaults, you can modify
mysql_install_db before you run it.
However, it is preferable to use
REVOKE to change the
privileges after the grant tables have
been set up. In other words, you can run
mysql_install_db, and then use
mysql -u root mysql to connect to the
server as the MySQL
root user so that you
can issue the necessary
If you want to install MySQL on several machines with the
same privileges, you can put the
REVOKE statements in a file
and execute the file as a script using
mysql after running
mysql_install_db. For example:
bin/mysql -u root < your_script_file
By doing this, you can avoid having to issue 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
REVOKE and 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, remove all the
.MYD files in the
mysql database directory. Then run the
mysql_install_db script again.
bin/mysqld_safe --user=mysql --skip-grant-tables &shell>
From mysql, manually execute the SQL commands contained in mysql_install_db. Make sure that you run mysqladmin flush-privileges or mysqladmin reload afterward to tell the server to reload the grant tables.
Note that by not using mysql_install_db, you not only have to populate the grant tables manually, you also have to create them first.