Mysql – Table doesn’t exist in engine

MySQL

I am getting a weird error in my mysql database:

SELECT * FROM mytable

returns:

ERROR 1932 (42S02): Table 'mydb.mytable' doesn't exist in engine

I can confirm that the tables do indeed exist on local file system and show tables; does indeed return the tables I am interested in.

show tables;

+-----------------+
| Tables_in_mydb  |
+-----------------+
| presets         |
| mytable         |
+-----------------+

And the select:

select * from mytable;

Table 'mydb.mytable' doesn't exist in engine. 

Error makes absolute no sense and I've been working with this tables a couple of days ago without any problems. I haven't moved the tables. What should I do?

Before that error above showed up I was getting an error:

Access denied for user 'root'@'localhost' (using password: YES),
but I successfully updated the password. I have no idea what triggered this error because I haven't played with passwords.

However, when I tried to fix this error I have set permissions on /Applications/XAMPP/xamppfiles/var/mysql to read/write to everyone.

I have physical access to .frm and .ibd files of the database. I believe I use InnoDB storage engine.

UPDATE:

show table status gives back a really weird outout:

+-----------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+------------------------------------------------------+
| Name            | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time         | Update_time | Check_time | Collation         | Checksum | Create_options | Comment                                              |
+-----------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+-------------------+----------+----------------+------------------------------------------------------+
| preset          | NULL   |    NULL | NULL       | NULL |           NULL |        NULL |            NULL |         NULL |      NULL |           NULL | NULL                | NULL        | NULL       | NULL              |     NULL | NULL           | Table 'mydb.preset' doesn't exist in engine          |
| mytable         | NULL   |    NULL | NULL       | NULL |           NULL |        NULL |            NULL |         NULL |      NULL |           NULL | NULL                | NULL        | NULL       | NULL              |     NULL | NULL           | Table 'mydb.mytable' doesn't exist in engine         |

UPDATE 2
ls -lh /Applications/XAMPP/xamppfiles/var/mysql/ returns

-rwxrwxr--   1 _mysql  706   135K Jan  4  2017 My-MBP.err
-rwxrwxr--   1 _mysql  706   897K Jan 27 00:46 My-MacBook-Pro.local.err
drwxrwxr-x  33 _mysql  706   1.1K Feb 20  2017 abraham
drwxrwxr-x   7 _mysql  706   238B May 27  2016 accounts
-rwxrwxr--   1 _mysql  706    16K Jan 27 00:46 aria_log.00000001
-rwxrwxr--   1 _mysql  706    52B Jan 27 00:46 aria_log_control
drwxrwxr-x  23 _mysql  706   782B Jun 11  2017 ch7
drwxrwxr-x  31 _mysql  706   1.0K Jun 19  2017 coronel_2
drwxrwxr-x   5 _mysql  706   170B May 29  2017 emails
-rwxrwxr--   1 _mysql  706   5.0M Jan 27 00:46 ib_logfile0
-rwxrwxr--   1 _mysql  706   5.0M Nov 24  2015 ib_logfile1
-rwxrwxr--   1 _mysql  706    74M Jan 27 00:46 ibdata1
drwxrwxr-x   5 _mysql  706   170B Aug 28 17:44 jsonTest
-rwxrwxr--   1 _mysql  706     0B Nov 24  2015 multi-master.info
drwxrwxrwx   9 _mysql  706   306B Jan 26 11:40 mydb
drwxrwxr-x  89 _mysql  706   3.0K Jan 15 11:29 mysql
drwxrwxr-x  13 _mysql  706   442B May 30  2017 payments_ipndb
drwxrwxr-x   3 _mysql  706   102B Jan 15 11:29 performance_schema
drwxrwxr-x  41 _mysql  706   1.4K Jan 15 11:29 phpmyadmin
drwxrwxr-x   2 _mysql  706    68B Jan 15 11:28 test
drwxrwxr-x   5 _mysql  706   170B Jun 11  2017 tracking
drwxrwxr-x   9 _mysql  706   306B May 17  2017 tutorial
drwxrwxr-x   9 _mysql  706   306B Feb 21  2017 users

and ls -lh /Applications/XAMPP/xamppfiles/var/mysql/mydb/ returns

-rw-rw-rw-  1 _mysql  706    65B Sep  4 17:57 db.opt
-rw-rw-rw-  1 _mysql  706   1.8K Sep  8 18:20 preset.frm
-rw-rw-rw-  1 _mysql  706    96K Sep  9 20:53 preset.ibd
-rw-rw-rw-  1 _mysql  706   1.0K Jan 11 16:15 mytable.frm
-rw-rw-rw-  1 _mysql  706   128K Jan 11 21:02 mytable.ibd

.err file contains these messages:

[Warning] InnoDB: Cannot open table mydb/mytable from the internal data dictionary of InnoDB though the .frm file for the table exists. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html for how you can resolve the problem.

Even with that link, I am still unsure of what to do.

UPDATE:

I can confirm that the error comes from reinstalling XAMPP. I've created a new table, and I could use it normally. Than I reinstalled the xampp, and the newly created table is not accessible anymore, returning the same error as all the other tables: Table doesn't exist in engine.

I also get the same error in error logs:
[Warning] InnoDB: Cannot open table mydb/newlycreatedtable from the internal data dictionary of InnoDB though the .frm file for the table exists.
I still don't know how to solve it.

Best Answer

Disclaimer: Please read the whole answer to the end before you perform any modifications. Please backup everything before you change the permissions and/or owners. You are changing permissions at your own risk

Possible Root Cause

Changing the permissions on the .../var/mysql directory isn't the best idea.

However, when I tried to fix this error I have set permissions on /Applications/XAMPP/xamppfiles/var/mysql to read/write to everyone.


What MySQL Prefers

MySQL prefers the following directory permissions:

0700 (-RWX------)

MySQL prefers the following file permissions:

0660 (-RW-RW----)

By default, MySQL creates database directories with an access permission value of 0700.

...and...

The default UMASK and UMASK_DIR values are 0660 and 0700, respectively.

Reference: B.5.3.1 Problems with File Permissions


Fixing Permissions

To alter the directory and file permissions you would have to set off two commands like this:

Directory Permissions

bash> find /Applications/XAMPP/xamppfiles/var/mysql -type d -exec chmod 0700 {} \;

In the directory /Applications/XAMPP/xamppfiles/var/mysql find all directories and modify the directory permissions to -rwx------

File Permissions

bash> find /Applications/XAMPP/xamppfiles/var/mysql -type f -exec chmod 0660 {} \;

This translates to: In the directory /Applications/XAMPP/xamppfiles/var/mysql find all files and modify the directory permissions to -rw-rw---

Reference: How do I set chmod for a folder and all of its subfolders and files in Linux Ubuntu Terminal? [clsoed]


Owner?

You should have reset everything the way MySQL prefers it, unless you modified the owner of the .../var/mysql sub-directories and files, which should normally belong to the mysql linux user and equally to the mysql group.

In the case that the files and directories no longer belong to mysql mysql then you might have to reset the owner and group using:

bash> chown -R mysql mysql /Applications/XAMPP/xamppfiles/var/mysql

Individual File and Directory

You might want to consider looking at the permissions of that one file.


Final Observations

Looking at your directory listing I noticed that the user is set to _mysql (with underscore) and the group is set to 706. This might be because the linux group mysql has been deleted and the user _mysql changed.

Is the group mysql displayed if you issue the following command:

bash> cat /etc/group

Possible output:

mysql:x:117:

Does the user mysql exist when you type the following command:

bash> cat /etc/passwd

Possible output:

mysql:x:109:117:MySQL Server,,,:/home/mysql:/bin/bash

Note that the mysql user (109) belongs to the mysql group (117), which matches the ID from the cat /etc/group command.

Please Note:
Running the CHMOD and CHOWN commands will only reset the permissions correctly if the user and group exist. If the user and group exist, then you might be able to reset the permissions and owners to the correct values.


Last Resort

If all else fails you might want to consider re-installing your whole MySQL environment.


Last Resort 2

After reading the newest comments and updates to question there is a possible other solution

Reinstalling the XAMPP stack apparently does not remove all previous *.frm files containing your previously created tables.

However, reinstalling the XAMPPP stack will not allow you to access the previously accessible objects. This is because the files/tables are no longer referenced in the system catalogues. This is why you are receiving an error message when you try to select from your tables.

You might achieve a partial restore of the data and/or table definitions with the MySQL Utilities 1.5 which contain the following tool:

5.10 mysqlfrm — File reader for .frm files.

The tools is documented as follows:

...
A diagnostic mode is available by using the --diagnostic option. This switches the utility to read the .frm files byte-by-byte to recover as much information as possible. The diagnostic mode has additional limitations in that it cannot decipher character set or collation values without using an existing server installation specified with either the --server or --basedir option. This can also affect the size of the columns if the table uses multibyte characters. Use this mode when the default mode cannot read the file, or if a MySQL server is not installed on the host.
...

This might be your last resort to retrieving the information from your *.frm files in your broken MySQL instance.