4

Same database imported 3 three times after empty the entire database and surprisingly every time it shows different number of records. Why?

1st time import: enter image description here

2nd time import: enter image description here

3rd time import: enter image description here

It is not right to trust on Rows count as shown in picture it show approxmiate value as error suggested. So the question is how can we ensure that database is right and no record missing? note: short-cut require can't use count with each table it will lots of time.

5 Answers 5

11

MySQL is, surprisingly, really bad at numbers. For InnoDB tables those are often estimates of how many rows it contains and they can be wildly wrong.

The way it computes the numbers you're seeing is by taking the total size of the table data and dividing by the average row size in bytes. This is usually a good enough approximation of your data, but it can be very misleading, off by a factor of up to 100.

The only way to know for sure is to do COUNT(*), something that can take some time to compute on a very active table.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, I can ensure every table by executing this query is there any shortcut?
There's no short-cut. On a server that's idle this will usually take milliseconds per table. On one with extremely heavy write activity it can take upwards of minutes, it really depends. Try it out and see how it performs for you. The numbers you're seeing there are quick and dirty, they rarely take long to produce.
i try it on everytable its time consuming
It depends on your computer hardware and your InnoDB tuning parameters. If the InnoDB engine is starved for memory performance might not be that great. There's a large section in the manual devoted to InnoDB parameters as well as many guides on the internet in general. These tables all have a PRIMARY KEY?
concludingly i have to execute query for every table in order to ensure it. thanks
4

Tools like phpmyadmin/adminer always picks the row count from INFORMATION_SCHEMA. In case of InnoDb storage engine the row count is a rough estimate, it is never the exact value. The table_rows which phpmyadmin picks which is never accurate for Innodb

SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'table_name'; 

For exact value we need

SELECT count(*) FROM 'table_name'; 

For reference: http://dev.mysql.com/doc/refman/5.7/en/tables-table.html

1 Comment

Thanks, I can ensure every table by executing this query is there any shortcut?
4

You'll notice that all of the "negative mysql records" This isn't a negative sign its ~, which means approximately. if you want actual count use

SELECT count(*) FROM 'table_name'; 

1 Comment

Thanks, I can ensure every table by executing this query is there any shortcut?
2

I wouldn't rely on comparison of numbers with a tilde (~) as prefix.~ means approximation.

Based on bencoder response to this phpMyAdmin - What a tilde (~) means in rows column? the approximation can vary a lot.

To check the real number of rows imported use: select count(*) from TABLE_NAME

2 Comments

Thanks, I can ensure every table by executing this query is there any shortcut?
A nice solution is reported from Nathan on this question stackoverflow.com/questions/286039/…. (Sorry but I cannot paste the code here because is not correctly parsed)
1

The number you are seeing is approximation. To get the actual number JUST CLICK ON THE NUMBER. You will see the actual number. You do not need to run any query to view actual row number.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.