Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Mysqltuner showing fragmented table on new Innodb table

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
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…

839 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