Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

MariaDB ERROR 1932 (42S02) Table doesn't exist in engine: SHOW TABLES lists the table but InnoDB does not know it

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

ERROR 1932 (42S02): Table 'shop.orders_archive' doesn't exist in engine means the server holds a definition for the table, in its .frm file, but the InnoDB storage engine has no record of that table. MariaDB's page for error 1932 says that with InnoDB this "usually means that the .frm file, or the .frm and .ibd files, were copied into the data directory by hand". Save the files, then either drop a table you do not need or import the tablespace of one you do.

What the error means

MariaDB's page for error 1932 lists the code, SQLSTATE 42S02, the symbol ER_NO_SUCH_TABLE_IN_ENGINE and the text "Table '%-.192s.%-.192s' doesn't exist in engine". Its explanation: "The server has a definition of the table, in the table's .frm file, but the storage engine doesn't know the table. The table is listed by SHOW TABLES, but every statement that opens it fails". It adds "InnoDB knows only the tables in its data dictionary, so it can't use copied files without an import."

The InnoDB System Tablespaces page says "InnoDB uses the system tablespace to store the data dictionary, change buffer, and undo logs", and that tablespace is by default the ibdata1 file. Our own reading: a copy of the data directory made without that file would carry tables that the copied dictionary does not list.

Our own reading of the MariaDB 10.11.10 source: handler::print_error in sql/handler.cc turns the engine code HA_ERR_NO_SUCH_TABLE into this message, and ha_innobase::open in storage/innobase/handler/ha_innodb.cc returns that code when InnoDB cannot find the table in its dictionary. That matches the page.

Two other errors carry different texts. The page says "A table whose .ibd file is missing gives a different error", error 1030 with Got error 194 "Tablespace is missing for a table" from storage engine InnoDB, and "A table without a .frm file gives error 1146".

Likely causes

Cause What you see How to confirm
.frm and .ibd files copied in by hand The table is listed, every statement on it fails No row for it in INFORMATION_SCHEMA.INNODB_SYS_TABLES
A leftover .frm after InnoDB's files were deleted and recreated Same The error log says InnoDB cannot find the table "though the .frm file for the table exists"
A data directory copied without the InnoDB system tablespace and log files, or while the server ran (the error page says to copy it again with the server stopped, including those files) Several tables fail together (our own reading) ibdata1 is absent from the copied directory (our own reading)
A different fault Error 1030 with 194, or error 1146 The text differs from error 1932

Prove the cause before changing anything

All of these only read.

  1. Take the schema and table from the message: shop and orders_archive.
  2. Confirm the server lists it:
SHOW TABLES FROM shop;
  1. Ask InnoDB. The page for the data dictionary uses this form. Our own advice: reading this table may need a privilege such as PROCESS; if the query is refused, ask the database owner to run it.
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE 'shop/%';

Our own reading: a result with no row named shop/orders_archive means InnoDB has no dictionary entry for the table, which fits the page's statement that "the storage engine doesn't know the table".

  1. Look at the files. Read the data directory from SELECT @@datadir;, then:
ls -l /var/lib/mysql/shop/orders_archive.*

Our own reading: an .frm and an .ibd file with no dictionary row point to files copied in by hand, the cause the page names as the usual one.

  1. Read the server's error log for a line such as "Cannot find table test/x from the internal data dictionary", which the page for the data dictionary shows with the continuation "of InnoDB though the .frm file for the table exists."

  2. Find out where the files came from and whether a copy came from FLUSH TABLES ... FOR EXPORT. The import route below depends on it.

  3. Read the server version. Our own advice, because the import route below depends on it:
SELECT VERSION();

Fix

Choose by what the table is.

The table is not needed: drop it

MariaDB's page says: "If the table isn't needed, remove it with DROP TABLE. This removes the leftover .frm file."

First save the current state. Copy only the files that step 4 listed. The directory /data/saved-tablespaces/ must exist and be writable by the account that runs cp. If it does not exist, create it first, as its own step; this adds an empty directory and changes nothing else:

mkdir -p /data/saved-tablespaces

Then copy the files:

cp -p /var/lib/mysql/shop/orders_archive.frm /var/lib/mysql/shop/orders_archive.ibd /data/saved-tablespaces/

Risk: the next statement drops the table shop.orders_archive and removes its leftover .frm file. The server will no longer list the table. A statement cannot undo it; the saved copies are the only record of its definition and any data in the .ibd file.

Drop it:

DROP TABLE shop.orders_archive;

To undo it: copy the saved files back into the schema directory, then list the table again. Our own reading: the table is then back in the listed-but-failing state it was in before.

Risk: if you need to back out, the next command copies the saved files into the schema directory while the server runs. That hand copy is the same action that caused the fault, so the table is listed again and fails with ERROR 1932 as before. Our own advice: stop here and decide between the import and a drop.

cp -p /data/saved-tablespaces/orders_archive.frm /data/saved-tablespaces/orders_archive.ibd /var/lib/mysql/shop/

The table is needed and you have its exported files: import the tablespace

The page says: "If you have the table's .frm, .ibd and .cfg files from FLUSH TABLES … FOR EXPORT, import the table with ALTER TABLE … IMPORT TABLESPACE. From MariaDB 11.2, this works directly on the copied files." The File-Per-Table Tablespaces page marks its simplified workflow as starting with MariaDB 11.2.1, while the error page says 11.2; use 11.2.1 as the boundary. Use this route only on that version or later, as read in step 7, and only for files that came from FLUSH TABLES ... FOR EXPORT.

The statement is the last part of the page's workflow: the three files orders_archive.frm, .ibd and .cfg must already be in /var/lib/mysql/shop/. Confirm that first with a read-only listing, which also shows which files exist:

ls -l /var/lib/mysql/shop/orders_archive.*

First save the current state. Copy only the files that the listing shows. The directory /data/saved-tablespaces/ must exist and be writable; if you have not created it in the drop route above, run the same mkdir -p /data/saved-tablespaces first, as its own step:

cp -p /var/lib/mysql/shop/orders_archive.frm /var/lib/mysql/shop/orders_archive.ibd /var/lib/mysql/shop/orders_archive.cfg /data/saved-tablespaces/

Risk: the next statement imports the tablespace file of shop.orders_archive into InnoDB. Our own reading: no statement undoes an import, so the saved files are the only copy of the earlier files. A mismatch between the file and the table definition stops it with an error such as ERROR 1808 (HY000): Schema mismatch. The File-Per-Table Tablespaces page says a tablespace "can only be imported into tables that were created with the same row format as the original table".

Import it:

ALTER TABLE shop.orders_archive IMPORT TABLESPACE;

After an import, the saved files in /data/saved-tablespaces/ are the only copy of the earlier files. To go back to them, stop and decide with the database owner; no steps for that are given here.

For versions older than 11.2 the page says to "first create an empty table with the same definition and run ALTER TABLE … DISCARD TABLESPACE, then copy the .ibd and .cfg files and import them". The exact statements are on the File-Per-Table Tablespaces page. Our own reading: a leftover .frm would block the first of them, because the table name is already taken.

The whole data directory was copied

The page says "copy it again with the server stopped, including the InnoDB system tablespace and log files, or restore it from a backup made with mariadb-backup." That is the vendor's remedy; a full copy with the server stopped is a larger step than these statements. A server that will not start after such a copy is covered in MySQL will not start after a crash: InnoDB errors and innodb_force_recovery used safely, and the version rules for a backup restore in MariaDB physical backups with mariadb-backup: prepare, restore and version rules.

Example (illustrative): On db01, which runs a MariaDB release from 11.2.1 onward, an engineer copies orders_archive.frm, .ibd and .cfg from app01 into /var/lib/mysql/shop/ while the server runs. SHOW TABLES FROM shop; lists orders_archive. SELECT * FROM shop.orders_archive; fails with ERROR 1932 (42S02): Table 'shop.orders_archive' doesn't exist in engine. The INNODB_SYS_TABLES query returns rows for the other shop tables and none for shop/orders_archive. The three files came from FLUSH TABLES ... FOR EXPORT on app01, so the engineer saves them to /data/saved-tablespaces/ and runs the import.

Confirm the fix

  1. After an import, SELECT COUNT(*) FROM shop.orders_archive; returns a count, and the count equals the count on the source taken at export time.
  2. The INNODB_SYS_TABLES query now returns a row named shop/orders_archive.
  3. After a drop, SHOW TABLES FROM shop; no longer lists the table.

What to watch afterwards

  • Move InnoDB tables between servers with FLUSH TABLES ... FOR EXPORT, the file copy and IMPORT TABLESPACE, or with mariadb-backup; the page says the transport route can be used "when restoring partial backups".
  • The File-Per-Table Tablespaces page warns that differing ROW_FORMAT values, differing temporal-column storage formats and foreign keys block an import. It says "DISCARD on a table with foreign key constraints is only possible after disabling foreign_key_checks".
  • Compare table counts between source and target after any restore.

Risks and limits

  • These commands have not been run or lab-tested.
  • Importing needs files from FLUSH TABLES ... FOR EXPORT; an .ibd copied from a running server may not be consistent.
  • The message and code path are read from 10.11.10 and may differ in other releases.
  • MySQL 8.4 lists error 1146 as "Table '%s.%s' doesn't exist"; the cause described here comes from MariaDB's pages and applies to MariaDB only.

Sources