Solved

Mysqltuner showing fragmented table on new Innodb table

Posted on 2013-05-19
4
773 Views
Last Modified: 2013-05-20
I just installed MySQL 5.6 and created a database and a table.  I ran the mysqltuner script against it and it says that there is 1 fragmented table.

How is this possible with an empty table?  I have not specified innodb_file_per_table and it's storing the table and database in ibdata1 (or whatever the default store is called).

Is the mysqltuner reporting false data or did I miss something?

Thanks!
0
Comment
Question by:jelinek
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
nemws1 earned 500 total points
ID: 39181227
It's throwing this because MySQL allocates a minimum size for INNODB tables, if I remember right, around 4Mb.  The tuner is throwing an error because the difference between the data amount (zero) and the allocated size (4mb) is 4mb!  It thinks you have 4mb of fragmented space, even though it is just unallocated.

In my own performance scripts, I won't throw out a fragementation error unless the *data* size (in your case, zero) is at least 25mb for this exact issue.
0
 

Author Closing Comment

by:jelinek
ID: 39181345
Very thorough explanation.  Thanks for the lesson on lesson on minimum table size and mysqltuner!
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39181615
Just a little more info.  You can see this in play if you run the following query to find fragmentation in tables:

SELECT
    table_schema
    , table_name
    , CONCAT(ROUND(data_length / ( 1024 * 1024 ), 2), 'MB') AS Data
    , CONCAT(ROUND(data_free  / ( 1024 * 1024 ), 2), 'MB') AS Free
    , (data_free / data_length) * 100 AS pfrag
    , data_length
FROM information_schema.TABLES
WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql')
    AND (data_free / data_length) * 100 > 0
;

Open in new window


If you look at the 'Free' column - you should see a *bunch* of '4.00MB' tables.  Of course, it's impossible for so many table to have the exact free space, so it must be a pre-allocation (you'll see some 3.00MB and 5.00MB or whatever in there as well - but they're all an even number).

Here's my usual 'find fragmentation tables' script, which tries to be a bit smarter about all this:

--
-- Table Fragmentation
--   run with '-r' to get correctly formatted output
--

-- minimum table size in megabytes
--   DO NOT set below 10!!
SET @min_data_size = 20;

-- minimum fragmentation percentage - industry standard minimum in 25
SET @min_frag_perc = 5;

--
-- Main query
SELECT
    CONCAT("-- "
           , "Table "
           , table_schema
           , "."
           , table_name
           , " fragementation is: "
           , ((data_free / data_length) * 100)
           , "\n"
           , "OPTIMIZE TABLE `"
           , table_schema
           , "`.`"
           , table_name
           , "`;") AS "--\n-- Fix MySQL Table Fragmentation\n--"
/*
    , table_schema
    , table_name
    , CONCAT(ROUND(data_length / ( 1024 * 1024 ), 2), 'MB') AS Data
    , CONCAT(ROUND(data_free  / ( 1024 * 1024 ), 2), 'MB') AS Free
    , (data_free / data_length) * 100 AS pfrag
    , data_length
*/
FROM information_schema.TABLES
WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql')
    AND data_free > 0
    AND data_length > (@min_data_size * 1024 * 1024)
    AND ((data_free / data_length) * 100) > @min_frag_perc
;

Open in new window

0
 
LVL 28

Expert Comment

by:FishMonger
ID: 39181658
I have not specified innodb_file_per_table and it's storing the table and database in ibdata1

You should enable  innodb_file_per_table.  It will make it easier/faster when it comes time to optimize the tables, especially if you have a fair number of indexes and when your tables grow in size (over 1 million rows) to the point where you need to partition the tables.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question