Initializing MySQL database after installation
Please read whole tutorial before doing anything. These commands were tested on a Linux environment (running MySQL 4.1.22) and should work on most Unix machines too. However, they will have to be modified a little for Windows environment.
If you have an empty data folder or you want to initialize/reinitialize MySQL server from scratch (possibly after dropping all existing databases) then use the following instructions (assuming you have root access or you can use sudo):
For this tutorial, I'll assume the data directory (where all the data was stored or has to be stored) is: /clients/example/mysql/data/. Now, execute the following commands from shell command line.
Replace data directory path with your own (will delete all your data, so think twice before you run the command):
sudo rm -drf /clients/example/mysql/data
Recreate data directory:
sudo mkdir /clients/example/mysql/data
If you are running MySQL as mysql user then do the following (replace mysql with your user name and group name):
sudo chown mysql:mysql /clients/example/mysql/data
If you have logging of any type enabled then you can also use the above commands (or slightly modify them) to delete, recreate, and assign proper privileges to them.
Now, run the MySQL installation script as follows (from inside the MySQL installation folder e.g. /opt/mysql
sudo ./scripts/mysql_install_db --user=mysql --datadir=/clients/example/mysql/data/
You should also give ownership to mysql user and group using the following command.
sudo chown -R mysql:mysql /clients/example/mysql/
That's it. Now, you can run your MySQL daemon using mysqld directly or using mysqld_safe (recommended).
Please feel free to use the comments form below if you have any questions or need more explanation on anything. Use the icons below to share this tutorial with your friends.