Solved

Mysqltuner showing fragmented table on new Innodb table

Posted on 2013-05-19
4
765 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
More Fun with XML and MySQL – Parsing Delimited String with a Single SQL Statement Are you ready for another of my SQL tidbits?  Hopefully so, as in this adventure, I will be covering a topic that comes up a lot which is parsing a comma (or other…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now