5

If you try to access a table in a database of type INNODB and MariaDB tells you it isn't here, you have a corrupted database.

(I am posting this question because all of the existing questions have been "closed" by various moderators and NONE of them have a real answer. They discuss the complexities of INNODB, and ultimately that you have to rebuild the entire database server through a torturous process.)

1 Answer 1

6

This may not work for everyone, but it did work for us on several occasions:

  1. Stop the database (service mysql stop)
  2. edit mysql.cnf so that under [mysqld] section it has the:

    [mysqld] 
    innodb_force_recovery = 1 
    
  3. Start the database (service mysql start) and in the logfile you will see it force loading the bad database/table

  4. log into the database server as root: mysql -u root

  5. run the command "show databases[ENTER]" to get a list of database

  6. run he command "drop [dbname][ENTER]" where [thedb] is the database you need to drop. It will drop it but will complain that it cannot delete the directory ./[thedb].

  7. Open a separate shell and go into /var/lib/mysql/[thedb]/ and remove the file(s) there.

  8. Stop the database (service mysql stop)

  9. Turn off the REPAIR mode by commenting out the line in mysql.cnf

    [mysqld]
    #innodb_force_recovery = 1 
    
  10. restart the database with the command:

    service mysql start[ENTER]
    

Voila.

Now recreate the database and restore from your backup.

Thanks, David

5
  • I'm a bit confused by step 7. Did you mean to say something about deleting a file or directory?
    – dbdemon
    Dec 6, 2017 at 9:52
  • I just re-re-read your comment. I am sorry for the confusion. I have cleaned up the text so it reads better.
    – TekOps
    May 3, 2019 at 20:21
  • That looks better, thanks for clarifying!
    – dbdemon
    May 3, 2019 at 21:32
  • In case this is useful to anyone: I skipped steps 1 to 3 and the solution still worked.
    – Tim Rogers
    Jun 8, 2020 at 15:46
  • For me, steps 1 to 3 were sufficient to drop the table properly. Thank you so much. Dec 19, 2022 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.