mySQL error: Table 'table' doesn't exist in engine - mysql

Out of the sudden I am getting a weird error on my mysql database tables.
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.
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 |

The SHOW TABLES result looks a little off. The box has a bit more space on the mytable line. Is it possible there's an invisible character in your tablename somehow? Maybe you created it wrong?

Related

Can anybody help me identify the error in this statement?

The table looks like this
mysql> DESCRIBE tenants;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| domain | varchar(255) | NO | UNI | NULL | |
| database | varchar(255) | NO | UNI | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
mysql> INSERT INTO tenants(name,domain,database) VALUES ('varun','varun.localhost','sms_varun');
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'database) VALUES
('varun','varun.localhost','sms_varun')' at line 1
I am using mysql Ver 8.0.30 for Linux on x86_64 (MySQL Community Server - GPL)
DATABASE is a reserved MySQL keyword (see here), so you will have to escape it in your insert statement (and forever) to make it work:
INSERT INTO tenants (name, domain, `database`)
VALUES ('varun', 'varun.localhost', 'sms_varun');
You should avoid using reserved MySQL keywords for your column and table names.

ERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes, when trying to retrieve data from a table

I am working on my local set up of a web application and I have to fetch all the items in a table, but when I do select * from my_table, it gives me this errorERROR 2020 (HY000): Got packet bigger than 'max_allowed_packet' bytes.
I have tried many options, some of which include:
-Setting max_allowed_packet in my \etc\mysql\mysql.conf.d\mysqld.cnf and \etc\mysql\mysql.conf.d\mysqldump.cnf(I am not using dump, but to be on safe side), to 1G then 2G etc.
-Also tried using set global net_buffer_length=1000000; and set global max_allowed_packet=1000000000; in mysql in terminal
I got a bit of success when I used mysql --max_allowed_packet=100M -u root - it gives all the data but the problem is it works only in the terminal, but I have to get data in my web application where it will not work.
The interesting thing is: I tried using limit, so when I use select * from my_table limit 200, it gives expected result(but 200 rows only). Total rows are approx 350, So the error is in data of higher rows than 200. To checkout size of row result I used following query:
select sum(row_size) from ( select char_length(id)+ char_length(code)+ char_length(name)+ char_length(url) +char_length(group)+ char_length(template)+ char_length(html) + char_length(association) + char_length(status) + char_length(created_at)+ char_length(updated_at) + char_length(html_generation_date) as row_size from myTable limit 311,1) as tbl1; Which gives me: 43095
while for limit 150,1 above query gives: 94428. So row size doesn't seem to be a problem.
I tried solutions given on MySQL Error 1153 - Got a packet bigger than 'max_allowed_packet' bytes and https://serverfault.com/questions/102564/error-2020-got-packet-bigger-than-max-allowed-packet-bytes-when-dumping-table.
Basically, I want to do something like this: myTable::model()->findAll(); in my PHP Yii app which is equivalent to select * from my_table and afterwards I can use the data to populate my list.
Table Schema is:
+----------------------+--------------+------+-----+-------------------+-----------------------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| code | varchar(150) | NO | | NULL | |
| name | varchar(150) | NO | | NULL | |
| url | varchar(255) | NO | | NULL | |
| group | int(11) | NO | MUL | NULL | |
| template | int(11) | NO | | NULL | |
| html | longtext | YES | | NULL | |
| association | varchar(100) | NO | | NULL | |
| status | tinyint(1) | NO | | NULL | |
| created_at | timestamp | NO | | CURRENT_TIMESTAMP | |
| updated_at | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| html_generation_date | timestamp | YES | | NULL | |
And the mysql version is: 14.14 Distribution: 5.7.26. DB engine is InnoDB.
Any help will be highly appreciated.

MySQL - i dont see data, but mysql says, that there are rows

I have table ip_per_nat_vlan, innodb format. When I give truncate table, table is empty.
Then I have php script, which fill data into this table.
When is this script finished without errors (simple insert statemets) situation is following:
select * from ip_per_nat_vlan;
Empty set (0.00 sec)
.
select count(*) from ip_per_nat_vlan;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
.
show table status;
+----------------------------------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+------------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| 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 |
+----------------------------------+--------+---------+------------+----------+----------------+-------------+-----------------+--------------+------------+----------------+---------------------+---------------------+------------+-----------------+----------+----------------+---------+
| ip_per_nat_vlan | InnoDB | 10 | Dynamic | 141291 | 100 | 14172160 | 0 | 6832128 | 25165824 | 143563 | 2017-12-24 16:26:40 | 2018-06-13 09:01:33 | NULL | utf8_unicode_ci | NULL |
MySQL says, that there should be 14172160 rows, but I dont see any. Where could be a problem? Transactions? But I dont see any running thread and no any fault.
Thank you. D
Structure of table is:
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ipAddress | varchar(255) | NO | UNI | NULL | |
| nat | int(11) | NO | | NULL | |
| vlan | int(11) | NO | | NULL | |
| district | varchar(255) | YES | | NULL | |
| idOblasti | int(11) | YES | | NULL | |
| type | varchar(255) | NO | | NULL | |
| macAddress | varchar(255) | NO | | NULL | |
+------------+--------------+------+-----+---------+----------------+
There are various ways to "count" rows in a table.
The normal way. Just count them.
select count(*) as table_rows from table_name ;
Accuracy: 100% accurate count at the time of the query is run.
using the information_schema tables
select table_rows
from information_schema.tables
where table_schema = 'database_name'
and table_name = 'table_name' ;
Accuracy: Only an approximation. If the table is the target of frequent inserts and deletes, the result can be way off the actual count. This can be improved by running ANALYZE TABLE more often.
Efficiency: Very good, it doesn't touch the table at all.
As count option is 100% accurate, your table doesn't contain any data.
Check your code and default commit option of MySQL.
Looks like you are inserting rows, but not committing them, check your index length.
Check more details here
https://dba.stackexchange.com/questions/151769/mysql-difference-between-using-count-and-information-schema-tables-for-coun
First thing, I am not sure how mysql run this line and produce the result
select count() from ip_per_nat_vlan
count() will return [Err] 1064.
count(*) or else a field name should be mentioned inside.

Clear error after removing .frm file

I have accidentally deleted a .frm file for a test table. The problem is that I can not drop this table and remove it from information_schema.
select * from information_schema.tables where table_name like 'testtesttest';
+---------------+--------------+--------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+-------------+------------+-----------------+----------+----------------+----------------------------------------------------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ENGINE | VERSION | ROW_FORMAT | TABLE_ROWS | AVG_ROW_LENGTH | DATA_LENGTH | MAX_DATA_LENGTH | INDEX_LENGTH | DATA_FREE | AUTO_INCREMENT | CREATE_TIME | UPDATE_TIME | CHECK_TIME | TABLE_COLLATION | CHECKSUM | CREATE_OPTIONS | TABLE_COMMENT |
+---------------+--------------+--------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+-------------+------------+-----------------+----------+----------------+----------------------------------------------------------+
| def | report | testtesttest | BASE TABLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Can't find file: './report/testtesttest.frm' (errno: 13) |
+---------------+--------------+--------------+------------+--------+---------+------------+------------+----------------+-------------+-----------------+--------------+-----------+----------------+-------------+-------------+------------+-----------------+----------+----------------+----------------------------------------------------------+
drop table report.testtesttest;
ERROR 1051 (42S02): Unknown table 'testtesttest'
Is there a way to tell mysql that such a table no longer exists?
Looks like that the following steps help:
touch /var/lib/mysql/report/testtesttest.{frm,ibd}
chown mysql:mysql /var/lib/mysql/report/testtesttest.frm
restart mysql
drop table report.testtesttest;

MySQL query very slow. Count(*) on indexed column

The table is in InnoDB table. Here is some information that might be helpful.
EXPLAIN SELECT COUNT(*) AS y0_ FROM db.table this_ WHERE this_.id IS NOT NULL;
+----+-------------+-------+-------+---------------+---------+---------+------+---------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+---------+--------------------------+
| 1 | SIMPLE | this_ | index | PRIMARY | PRIMARY | 8 | NULL | 4711235 | Using where; Using index |
+----+-------------+-------+-------+---------------+---------+---------+------+---------+--------------------------+
1 row in set (0.00 sec)
mysql> DESCRIBE db.table;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id | bigint(20) | NO | PRI | NULL | |
| id2 | varchar(28) | YES | | NULL | |
| photo | longblob | YES | | NULL | |
| source | varchar(10) | YES | | NULL | |
| file_name | varchar(120) | YES | | NULL | |
| file_type | char(1) | YES | | NULL | |
| created_date | datetime | YES | | NULL | |
| updated_date | datetime | YES | | NULL | |
| createdby | varchar(50) | YES | | NULL | |
| updatedby | varchar(50) | YES | | NULL | |
+--------------+--------------+------+-----+---------+-------+
10 rows in set (0.05 sec)
The explain query gives me the result right there. But the actual query has been running for quite a while. How can I fix this? What am I doing wrong?
I basically need to figure out how many photos there are in this table. Initially the original coder had a query which checked WHERE photo IS NOT NULL (which took 3hours+) but I changed this query to check the id column as it is a primary key. I expected a huge performance gain there and was expecting an answer in under a second but that seems to not be the case.
What sort of optimizations on the database do I need to do? I think the query is fine but feel free to correct me if I am wrong.
Edit: mysql Ver 14.14 Distrib 5.1.52, for redhat-linux-gnu (x86_64) using readline 5.1
P.S: I renamed the tables for some crazy reason. I don't actually have the database named db and the table in question named table.
How long is 'long'? How many rows are there in this table?
A MyISAM table keeps track of how many rows it has, so a simple COUNT(*) will always return almost instantly.
InnoDB, on the other hand works differently: an InnoDB table doesn't keep track of how many rows it has, and so when you COUNT(*), it literally has to go and count each row. If you have a large table, this can take a number of seconds.
EDIT: Try COUNT(ID) instead of COUNT(*), where ID is an indexed column that has no NULLs in it. That may run faster.
EDIT2: If you're storing the binary data of the files in the longblob, your table will be massive, which will slow things down.
Possible solutions:
Use MyISAM instead of InnoDB.
Maintain your own count, perhaps using triggers on inserts and deletes.
Strip out the binary data into another table, or preferably regular files.