Solved

Mysqltuner showing fragmented table on new Innodb table

Posted on 2013-05-19
4
796 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
[X]
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
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Foreword This article was written many years ago, in the days when PHP supported the MySQL extension (http://php.net/manual/en/function.mysql-connect.php).  Today (http://php.net/manual/en/migration70.removed-exts-sapis.php) you would not use MySQL…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

632 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