Skip to content

MySQL ERROR 1146 Table doesn't exist on cPanel: fixes

ERROR 1146 means MySQL found no table it could open under that name. Tell a dropped table from an invisible one on cPanel, then restore or reattach it.

ERROR 1146 (42S02): Table 'db.tablename' doesn't exist means MySQL or MariaDB looked up that table name and found nothing it could open. On a cPanel or WHM server that is true in two very different ways. Either the table is really gone, or its file is still in /var/lib/mysql/ while the data dictionary, the server’s internal list of tables, has no record of it. Both states print the same message and need opposite fixes: a restore in the first case, reattaching the tablespace in the second. Four commands tell them apart. The steps below run those four, then walk the four real repairs behind them: a letter-case mismatch in the name, the wrong database or WordPress table prefix, an orphaned InnoDB .ibd file, and a table that really was dropped.

What you’ll accomplish

  • A definite answer to whether the table exists on disk, in the dictionary, in both, or in neither.
  • A case-sensitivity check that catches the dump imported from a Windows or macOS dev box.
  • A working DISCARD / IMPORT TABLESPACE cycle for an orphaned .ibd, with its real preconditions stated up front.
  • The WordPress $table_prefix check that resolves a large share of 1146s on cPanel accounts.
  • A clear decision point for when to stop fiddling and restore from a logical dump instead.

Prerequisites

You need root or sudo on the server: the diagnosis reads /var/lib/mysql/, which a cPanel account user cannot list. A working mysql client with credentials that can read information_schema is assumed — as root, /root/.my.cnf usually supplies them, so the examples omit -u/-p.

Version matters more here than in most MySQL problems. MySQL 8.0 keeps its data dictionary in a transactional store (mysql.ibd) and has no .frm files at all. MariaDB 10.x still writes a .frm per table beside the .ibd, and exposes its InnoDB internals through information_schema.INNODB_SYS_TABLES where MySQL 8 uses INNODB_TABLES. Which one you are on changes the queries below and changes what a stray file on disk even means; MySQL versus MariaDB on cPanel covers how to tell and why cPanel servers land on one or the other.

Take a filesystem-level copy of the database directory before you run anything that writes. DISCARD TABLESPACE deletes the current .ibd outright, and there is no undo.

Throughout, cpuser_dbname stands for the real database name and wp_posts for the table in the error message. Substitute both.

How it works

Every table has two halves. One is the data dictionary — the catalogue the server consults when it parses SELECT * FROM wp_posts. The other is the tablespace on disk, an .ibd file for InnoDB with innodb_file_per_table on, or the .MYD/.MYI pair for MyISAM. When both halves agree, the table works. A 1146 is the server telling you the dictionary half came back empty. It says nothing at all about the disk half, which is exactly why the error is so often misread.

Three states of a MySQL table: dictionary and filesystem in sync, dictionary entry with no file, and a file with no dictionary entry, each with its repair

The two halves drift apart for mundane reasons. Someone rsyncs /var/lib/mysql/cpuser_dbname/ from an old server to a new one instead of taking a dump: the files land, InnoDB never hears about them, and every query returns 1146. A restore replays a partial dump and stops before the table it needed. A drop half-completes when the disk fills. Or nothing broke at all and the application is simply asking for a name that never existed on this server — a different case, a different prefix, a different database.

MyISAM is the reason the file-copy habit exists. Copying .frm, .MYD and .MYI between servers of the same version genuinely does work, because MyISAM keeps everything it needs inside those files. InnoDB does not: an .ibd carries a space ID and internal references that only mean something to the dictionary that created it. The same instinct that works for one engine silently corrupts the other, and most cPanel databases have been InnoDB by default for years.

Case is the other trap. On Linux, lower_case_table_names defaults to 0, meaning names are stored and compared exactly as written. Windows and macOS development machines default to 1 or 2, which lowercase names on the way in. A dump made on a laptop where MyTable and mytable were the same thing arrives on a cPanel server where they are not, and the application’s queries miss by a single capital letter. MySQL’s own identifier case sensitivity page documents the full matrix.

Decision tree from ERROR 1146 through SHOW TABLES, the datadir listing, and case comparison to four distinct fixes

Step-by-step

  1. Reproduce the error against the database you actually think it lives in. The message names a database; confirm you are querying that one and not the application’s guess.

    mysql -e "SELECT 1 FROM cpuser_dbname.wp_posts LIMIT 1;"

    Two different errors are possible and they mean different things. ERROR 1146 (42S02): Table 'cpuser_dbname.wp_posts' doesn't exist means the dictionary has no entry. ERROR 1932 (42S02): Table 'cpuser_dbname.wp_posts' doesn't exist in engine means something — usually a leftover .frm on MariaDB — advertised the table while InnoDB disowned it. A 1932 puts you straight on the orphan branch.

  2. Ask the dictionary what it holds, without a LIKE pattern. Pattern matching hides case problems; a plain list plus a case-insensitive grep exposes them.

    mysql -N -e "SHOW TABLES FROM cpuser_dbname;" | grep -i posts

    If this prints WP_Posts or wp_Posts, you have found the fault and step 6 is your fix. If it prints nothing, the dictionary genuinely has no entry under any case. If it prints wp_posts exactly, the table exists and the application is pointed somewhere else — go to step 5.

  3. List what is actually on disk. This is the half the error message never tells you about.

    ls -la /var/lib/mysql/cpuser_dbname/ | grep -i posts

    Expect either nothing, or a line like -rw-rw---- 1 mysql mysql 51380224 Sep 3 04:11 wp_posts.ibd. A file present here while step 2 printed nothing is the orphaned-tablespace case. No file at all, and no dictionary entry, means the table is genuinely gone: skip to step 9. Note the ownership too — a file owned by root was copied in by hand and MySQL cannot read it.

  4. Confirm the case setting on this host before you rename anything.

    mysql -e "SELECT @@lower_case_table_names, @@lower_case_file_system;"

    On a stock cPanel server you should see 0 and 0. That is the case-sensitive configuration, and it is the correct one for Linux. Resist the urge to change it: MySQL 8 refuses to start if the setting differs from the value the datadir was initialised with, and MariaDB will happily start and then fail to find half your tables.

  5. Check what the application is asking for. For WordPress, the prefix in wp-config.php must match the tables that exist.

    grep table_prefix /home/cpuser/public_html/wp-config.php
    mysql -N -e "SHOW TABLES FROM cpuser_dbname;" | grep -E '_(options|posts)$'

    The first command prints something like $table_prefix = 'wp_';. The second prints the real prefix in use, for example wp_a7f2_options. A mismatch between them produces a 1146 on the very first query WordPress makes, and the fix is to edit $table_prefix to match the tables — never to rename the tables, because the wp_*_user_roles option key and the capability meta keys in usermeta are built from the same prefix.

  6. Fix a case mismatch by renaming the table, not the server setting.

    mysql -e "RENAME TABLE cpuser_dbname.WP_Posts TO cpuser_dbname.wp_posts;"

    Silence means success. Re-run step 2 and confirm the name now reads exactly as the application spells it. If several tables came in with the wrong case, generate the statements rather than typing them:

    mysql -N -e "SELECT CONCAT('RENAME TABLE cpuser_dbname.\`', table_name, '\` TO cpuser_dbname.\`', LOWER(table_name), '\`;') FROM information_schema.tables WHERE table_schema='cpuser_dbname' AND BINARY table_name <> BINARY LOWER(table_name);"

    Read the output before you pipe it back into mysql.

  7. Confirm an orphaned tablespace against InnoDB’s own catalogue. On MySQL 8:

    mysql -e "SELECT t.NAME, t.SPACE, d.PATH FROM information_schema.INNODB_TABLES t LEFT JOIN information_schema.INNODB_DATAFILES d ON t.SPACE=d.SPACE WHERE t.NAME LIKE 'cpuser_dbname/%';"

    On MariaDB and MySQL 5.7 the same query uses INNODB_SYS_TABLES and INNODB_SYS_DATAFILES. An empty result set for a database whose directory is full of .ibd files confirms the orphan diagnosis. If the .ibd file you found in step 3 has no row here, InnoDB has never registered it.

    Then read the error log, which records the mismatch in words: where the MySQL error log lives on cPanel gives the exact path for your build.

    grep -iE 'tablespace|does not exist|orphan' /var/lib/mysql/$(hostname).err | tail -20
  8. Reattach the orphaned tablespace — if, and only if, the preconditions hold. This works when you have the table’s exact original CREATE TABLE (same columns, same indexes, same row format), the .ibd came from the same MySQL or MariaDB series and the same page size, and innodb_file_per_table was on at both ends. It does not work across MySQL 5.7 to 8.0, and an .ibd from MySQL 8 will not import into MariaDB or the reverse. Get the definition from a schema dump if you have one:

    mysqldump --no-data --single-transaction cpuser_dbname wp_posts > /root/wp_posts.schema.sql

    With the definition in hand, move the orphan aside, recreate the table, discard its new empty tablespace, put the original file back, and import it:

    mv /var/lib/mysql/cpuser_dbname/wp_posts.ibd /root/wp_posts.ibd
    mysql cpuser_dbname < /root/wp_posts.schema.sql
    mysql -e "ALTER TABLE cpuser_dbname.wp_posts DISCARD TABLESPACE;"
    cp /root/wp_posts.ibd /var/lib/mysql/cpuser_dbname/wp_posts.ibd
    chown mysql:mysql /var/lib/mysql/cpuser_dbname/wp_posts.ibd
    chmod 660 /var/lib/mysql/cpuser_dbname/wp_posts.ibd
    mysql -e "ALTER TABLE cpuser_dbname.wp_posts IMPORT TABLESPACE;"

    Query OK, 0 rows affected on the last line is success. A warning that the .cfg file is missing is expected when you copied the file by hand; MySQL then imports without verifying the schema, which is precisely why the definition must be right. The supported way to produce that .cfg on the source server is to hold a lock in an interactive session while you copy:

    FLUSH TABLES cpuser_dbname.wp_posts FOR EXPORT;
    -- copy wp_posts.ibd and wp_posts.cfg from a second shell now, then:
    UNLOCK TABLES;

    The lock ends with the session, so mysql -e cannot do this — the copy has to happen while the session is still open. MySQL documents the full set of restrictions under importing InnoDB tables.

  9. When there is no file and no entry, restore from a logical dump. This is the honest outcome for a genuinely dropped table, and it is also the right outcome whenever step 8’s preconditions do not hold. Pull just the one table out of a full dump:

    sed -n '/^-- Table structure for table `wp_posts`/,/^-- Table structure for table `/p' /backup/cpuser_dbname.sql > /root/wp_posts.sql
    tail -3 /root/wp_posts.sql
    mysql cpuser_dbname < /root/wp_posts.sql

    The tail should show a complete statement ending in a semicolon, not a truncated INSERT. Restoring one table beats restoring the whole database over a live site every time.

Validate it works

Prove both halves agree again, then prove the application agrees with both:

mysql -e "CHECK TABLE cpuser_dbname.wp_posts;"
mysql -e "SELECT COUNT(*) FROM cpuser_dbname.wp_posts;"
mysql -N -e "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='cpuser_dbname';"
ls /var/lib/mysql/cpuser_dbname/*.ibd | wc -l

CHECK TABLE should report status | OK. The row count should be a plausible number rather than 0. The last two numbers should be close — an InnoDB database has one .ibd per table, so a table count well below the file count means more orphans are waiting behind this one. Then load the application and watch the log while it runs:

tail -f /home/cpuser/logs/error_log

Troubleshooting

ERROR 1808 (HY000): Schema mismatch on IMPORT TABLESPACE. The message names the difference — row format, column count, or index count. Your CREATE TABLE is not the one that produced this .ibd. Find the real definition in an older dump or on the source server; guessing at it produces a table that imports and then returns wrong data.

ERROR 1812 (HY000): Tablespace is missing for table. The inverse desync: the dictionary has the entry, the file is gone. DROP TABLE clears the stale entry so you can reload from a dump. If the drop itself fails, start the server with innodb_force_recovery=1, drop the table, then remove the setting and restart normally.

IMPORT TABLESPACE succeeds but the table is empty or the server crashes reading it. The .ibd came from a different major version or a different innodb_page_size. There is no repair path for this; the file is not readable by this server. Restore from a dump instead.

The table name on disk looks mangled — my@002dtable.ibd. MySQL percent-encodes characters that are not filesystem-safe, so a table named my-table is stored that way. Your ls | grep missed it, not the server. Search on the encoded form, or list the directory in full.

Everything checks out but the application still gets 1146. It is connected to a different database than you tested. Print the credentials the application actually uses — for WordPress, grep DB_NAME /home/cpuser/public_html/wp-config.php — and re-run step 2 against that name. A staging database left behind by an old restore is the usual culprit.

When this is the wrong approach

If the whole datadir was copied from another server, stop repairing tables one at a time. Rebuild the source with mysqldump and reload it; you will spend less time than importing tablespaces one by one, and you will not be left wondering which tables imported with a mismatched definition.

If MySQL will not start at all, or is starting and stopping in a loop, 1146 is a symptom and not the problem. Address the startup failure first — a full disk is a common cause, and it can leave exactly this kind of half-dropped table behind.

If the database and its tables are all present but the cPanel account cannot see the database in its own interface, this is not a 1146 at all: it is the cPanel-to-MySQL mapping, which is repaired with a different tool entirely and leaves the tables untouched.

And if the table is genuinely gone with no dump anywhere, be direct about it with whoever owns the data. Undelete tooling for InnoDB exists, it is slow, it is not reliable, and the honest answer is usually that a backup policy needs fixing more than the table does.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.