My Initial MySQL db is Broken, Help!
Typically a backup or dump of a MySQL server includes all of the databases available, using the -A or –all-databases options. But what of restoring, and recovering that dump?
One can simply go to the target machine, and delete everything in the data directory, right? Oops, you didn’t delete the initial MySQL database did you? How about the special “information_schema”, MySQL’s data dictionary? The other option of course is to use mysqladmin:
SQL> mysqladmin -f -u root -p drop mydatabase
But still I’ve had cases where I’ve dropped parts or all of these initial MySQL databases. So what to do if you do?
Luckily MySQL comes with a shell script to save you in just such cases. It’s called mysql_install_db and can typically be found in /usr/bin. For Oracle folks you can almost think of this like the catalog.sql which in turn runs the sql.bsq file. It is illustrative to take a look at this shell script, and see what’s contained in there. You’ll learn a lot about the bootstrapping process.
MySQL has documentation on the mysql_install_db script.
So when you go to building your backup scripts, and are putting all the pieces in place, be sure to make a note of this script, and remember where it is. If you are providing instructions for recovery for Unix Admins who may not know MySQL particularly well, be sure there is a note, or even better yet, a call to this script in your own restore scripts.
