6

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.

  • Please provide SHOW TABLE STATUS; – Rick James Jan 26 '18 at 16:42
  • What about ibdata file on datadir (/Applications/.../xamppfiles/var/mysql ? Does it exists? – kriegu Jan 26 '18 at 16:46
  • there is an ibdata1 file in /Applications/.../xamppfiles/var/mysql – sanjihan Jan 26 '18 at 20:43
  • can you upload the output of the following comands? ls -lh /Applications/XAMPP/xamppfiles/var/mysql/ ls -lh /Applications/XAMPP/xamppfiles/var/mysql/mydb/ – kriegu Jan 29 '18 at 16:36
  • I've added the results of these 2 commands – sanjihan Jan 30 '18 at 23:08
1

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.

  • Thanks for a detailed answer! I've set the permissions as suggested, but that didn't change the issues. I am on a mac, so default mySQL owner is probably _mysql and not mysql. I've changed the group to _mysql too, but nothing changed. – sanjihan Feb 6 '18 at 9:58
  • I've deleted XAMPP and install it again, login as mysql -u root, and voila, databases are still there, show tables returns the tables, but when running a select statement: it still returns that the table doesn exist – sanjihan Feb 6 '18 at 10:28
  • I can confirm the error stems from reinstalling xampp. Still havent found the solution – sanjihan Feb 6 '18 at 21:45
  • I was on vacation, so I couldn't get back to you in due time. Sorry. After reading the latest comments and additions I have come to the following conclusion: Reinstalling the XAMPP stack apparently does not remove the previous *.frm files containing the previously available 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. Do you have a backup? – hot2use Feb 12 '18 at 13:20
  • Hope you had a great time! nope, no backup. I am not getting the data back am I? – sanjihan Feb 12 '18 at 14:37
0

Let's see how you created mytable. I suggest that this will work:

SELECT * FROM `mytable  `;

Please do not have spaces in table names. And avoid punctuation that could cause trouble. (Underscore is safe.)

  • 1
    This is just an artifact from replcing my real table name with mytable. It has nothing to do with the error. I've been using sql for years. This really isnt a syntax error. I've got the while server architecture written that suddenly stopped working because Table 'mydb.mytable' doesn't exist in engine error. – sanjihan Jan 26 '18 at 20:49
0

Is there any thins else in the mysql log?. check the table exists in the mysql schema:

select table_name from information_schema.tables where table_name='mytable';

also try to alter the table:

alter table mytable engine=innodb;

  • I'm getting in .err file: [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. I am still not sure what do to about it. CHECK TABLE mytable returns that the table doesn exits. – sanjihan Feb 2 '18 at 11:38
  • select table_name from information_schema.tables where table_name='mytable'; returns the table- it exists. alter table mytable engine=innodb; returns that the table doesnt exist. – sanjihan Feb 2 '18 at 11:43
  • What about the grants ? "select user, host from mysql.user where user=<yourueser>", and then "show grants for 'user'@'host' ;" – andres Feb 3 '18 at 14:19
  • What is the output from: `select 'a' || table_schema || 'a', 'a' || table_name || 'a' from information_schema.tables where table_name='mytable'; ? – Lennart Feb 5 '18 at 19:30
  • Command returns 0 and 0 for each column. – sanjihan Feb 6 '18 at 9:59
-1

I'm not a mysql guy, so this might not be the issue.

The error references the schema, your select statement doesn't. Try adding the schema or a two part object name. It looks as through your default schema is mydb, and you might have created the table in a different schema.

  • Syntax: select * from mydb.mytable; – Rick James Jan 26 '18 at 16:43
  • select * from mydb.mytable; returns the same error. – sanjihan Jan 26 '18 at 20:44

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.