How to check if table exists in MySql db?

How can I drop a table whose name is "logs/#sql-ib203"?

  • DROP TABLE logs/#sql-ib203 does not work due to '/': Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/#sql-ib203' at line 1 The table logs/#sql-ib203 appeared after a database crash (not enough disk space while re-indexing and deleting some attributes in a table in the logs database). SHOW TABLES does not list the table logs/#sql-ib203, but when trying to ALTER the table that was being changed during the crash MySQL complains about the existence of the table logs/#sql-ib203: ERROR 1050: Table 'logs/#sql-ib203' already exists SQL Statement: ALTER TABLE logs.srv_logs DROP COLUMN filenum , DROP COLUMN agent , DROP COLUMN ip , DROP COLUMN event_source I use MySQL 5.6.12-winx64 and InnoDB.

  • Answer:

    You can quote object identifiers with `backticks`, however "logs/" is the directory for the "logs" database within the mysql datadir, and "logs/#sql-ib203" is referring to the table "#sql-ib203" in database "logs". I assume "#sql-ib203" is an internal/temporary table mysql was using to re-index.  You could try: DROP TABLE `logs`.`#sql-ib203`; But I doubt that will work.  Open your mysql datadir and see what data files exist for the table, there should be "mysql_datadir/logs/#sql-ib203.frm" If you're using innodb_file_per_table you should also have the file "mysql_datadir/logs/#sql-ib203.ibd" You're most likely missing one of them.  Manually deleting the files usually works, although I've had a case where the only way I could fix it was by dropping the database.  If all else fails you can either dump, drop and recreate the logs database, or create a new database, copy schema and data over, and drop the logs database.

Rob Johnson at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.