6

Today, i was absent minded and instead of droping the databases i wanted I wrote

drop database mysql;

What do i do now!?! i didnt do anything else since and i havent closed my session.

Luckily this is just my local computer with no real data. Should i delete mysql data folder? can i undo it? is there a cmd i can do to fix it? is there no real problem and i am freaking out for nothing?

-edit- ok so it WAS my server. Lucky its MY server and not the company server. I only have sites no one visits anyways. Since it was the server, i had twice a day dumps of sites that does rarely changes. I tried using my dump script to dump the db but it got an error. I figure its ok and hasnt been touched in days so i tried to restore it with this

gunzip < mybackup.sql.gz | mysql

I got the error

ERROR 1146 (42S02) at line 12: Table 'mysql.time_zone_name' doesn't exist

Now that i cant restore, what do i do?

splattne
  • 28,348
  • 19
  • 97
  • 147
  • dupe of http://stackoverflow.com/questions/2589630/mysql-undo-drop-database ? – Sirex Feb 11 '11 at 11:43
  • Sirex: Not at all. If i drop a db, i can restore it. I dropped this specific database and i cant do ANYTHING –  Feb 11 '11 at 11:47
  • Whats sad is i know how to fix this under windows... i just unzip the windows noinstall package. –  Feb 11 '11 at 14:14
  • Funny how we have 8upvotes (and 9 cause i did it too) on that idiot tag comment and only 3ppl actually upvoted the question. Hey... someone removed the idiot tag.... –  Feb 12 '11 at 01:43

1 Answers1

10

The solution you want (and this should work) is to run mysql_install_db as root. or dpkg-reconfigure mysql if you're a deb/ubu user.

Manpage description:

mysql_install_db initializes the MySQL data directory and creates the system tables that it contains, if they do not exist.

Tom O'Connor
  • 27,440
  • 10
  • 72
  • 148
  • 4
    Remember that users, permissions and privileges will need to be redone, dropping the mysql table made it all go away. – coredump Feb 11 '11 at 12:14
  • I reckon you could probably reimport those from a backup though. mysql_install_db does the hard part. – Tom O'Connor Feb 11 '11 at 12:21
  • Tom O'Connor: I am not sure about that. i am getting errors such as `error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)`. I killall mysqld, purged mysql-server and apt-get install mysql-server. I had to hand restart it because i didnt see any ps up. and when i did i got the error above –  Feb 11 '11 at 12:23
  • I then tried... well i'll just paste it. http://www.pastie.org/1552500 –  Feb 11 '11 at 12:26
  • Reinstalling is always a nice way to fix it too. – Tom O'Connor Feb 11 '11 at 12:26
  • do the purge, delete all dirs related to mysql and the databases and then reinstall. – coredump Feb 11 '11 at 12:32
  • ok i did that. reinstalled. No luck then wrote. # mysql_install_db FATAL ERROR: Could not find SQL file '/usr/share/mysql/fill_help_tables.sql' # mysql_install_db --user=mysql --no-defaults FATAL ERROR: Could not find SQL file '/usr/share/mysql/fill_help_tables.sql' I'll turn off my server for a few hours. Maybe i'll be thinking more clearly then. Really a pain of a problem. –  Feb 11 '11 at 12:41
  • This isn't very helpful, but how about `apt-get purge mysql-server && apt-get install postgresql-8.4` ;) – Tom O'Connor Feb 11 '11 at 13:14