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.What MySQL Prefers
MySQL prefers the following directory permissions:
MySQL prefers the following file permissions:
...and...
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
File Permissions
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 themysql
linux user and equally to themysql
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: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 to706
. This might be because the linux groupmysql
has been deleted and the user_mysql
changed.Is the group
mysql
displayed if you issue the following command:Possible output:
Does the user
mysql
exist when you type the following command:Possible output:
Note that the
mysql
user (109) belongs to themysql
group (117), which matches the ID from thecat /etc/group
command.Please Note:
Running the
CHMOD
andCHOWN
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:
This might be your last resort to retrieving the information from your
*.frm
files in your broken MySQL instance.