How to create MySQL data directory with mysql_install_db
On a Debian 7 server, the MySQL database got corrupted, which caused the MySQL database to keep crashing. I was able to take a backup of the database following InnoDB Recovery instructions at
https://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
Once I have the Database backup taken, I took a backup of the MySQL data directory /var/lib/mysql and removed it.
To recreate the MySQL data directory, I run the mysql_install_db command, but it failed with the error message “FATAL ERROR: Could not find my-default.cnf”
root@srv01 ~ # mysql_install_db --defaults-file=/etc/mysql/my.cnf --user=mysql --datadir=/var/lib/mysql FATAL ERROR: Could not find my-default.cnf If you compiled from source, you need to run 'make install' to copy the software into the correct location ready for operation. If you are using a binary release, you must either be at the top level of the extracted archive, or pass the --basedir option pointing to that location. root@srv01 ~ #
It is fixed by copying /etc/mysql/my.cnf to /usr/share/mysql/my-default.cnf
cp /etc/mysql/my.cnf /usr/share/mysql/my-default.cnf
Back to MySQL