Solved

Mysqltuner showing fragmented table on new Innodb table

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please help me with my database modeling 7 37
PHP strip quotes and line feeds out of array 13 47
[MYSQL]: Delete is very slow 4 52
mysql joining from the same table 6 29
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Creating and Managing Databases with phpMyAdmin in cPanel.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

943 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

7 Experts available now in Live!

Get 1:1 Help Now