11

I can log into phpmyadmin and see databases very quickly. Once I click on one of them and try to see the tables list it's very slow. Is there anything I'm missing? I didn't have this situation before updating from Ubuntu 10.04 to Ubuntu 12.04.

4
  • Purge and reinstall php5-mysql package
    – Tachyons
    Dec 25, 2012 at 3:15
  • Is that particular database has any innoDB table that has lots of rows? Dec 25, 2012 at 3:17
  • yes, we use a lof of innoDB tables, some of them have millions rows. Dec 25, 2012 at 3:26
  • it's very slow in our staging env, but in production env it's quick enough Dec 25, 2012 at 3:26

9 Answers 9

11

Open the \config.inc.php file and append these two lines:

$cfg['MaxExactCount'] = 0;
$cfg['MaxExactCountViews'] = 0;

And of course, the second line can be skipped if there is not any view in the database.

0
7

This is because you have innoDB tables with lot of rows. InnoDB does not store the number of rows in a table but MyISAM does. So for each InnoDB table PHPMyAdmin invokes SELECT count(*) FROM query which is very slow if number of rows is very high. To resolve this you should edit config.inc.php file and set $cfg['MaxExactCount']. This will invoke count(*) sql for tables that has less MaxExactCount rows.

$cfg['MaxExactCount'] = 20000;

Meaning form phpmyadmin manual

For InnoDB tables, determines for how large tables phpMyAdmin should get the exact row count using SELECT COUNT. If the approximate row count as returned by SHOW TABLE STATUS is smaller than this value, SELECT COUNT will be used, otherwise the approximate count will be used.

3
  • default value of 'MaxExactCount' is 20000, we also try to decrease it to 2000, didn't work :( Dec 25, 2012 at 3:37
  • oh, I find the slow command. "SHOW TABLE STATUS FROM db_staging"; phpmyadmin will execute this command when loading table list. It take 7 seconds to finish this command. Dec 25, 2012 at 5:36
  • I had to set $cfg['MaxExactCount'] to 0 for it to work as 20000 was not working. $cfg['MaxExactCount'] = 0;
    – IvanD
    Sep 26, 2013 at 5:11
6

Another source of slowness for phpMyAdmin running on a local server comes from its apparent ignoring of the hosts file. Try changing any occurrences of "localhost" in config.inc.php to "127.0.0.1". It created a great speedup for me on a Windows computer.

1
  • 1
    Wow, that really makes a huge difference, thank you for sharing this tip! It was almost unusably slow before changing $cfg['Servers'][$i]['host'] = 'localhost; to $cfg['Servers'][$i]['host'] = '127.0.0.1';
    – JoLoCo
    May 19, 2020 at 2:26
2

In case when you have several VIEWS with lots (>10^5) of records it works terribly slow even when MaxExactCountViews and MaxExactCount both set to 100.

Find

'static public function countRecords'

in

libraries\Table.class.php

, put following code in begining of this method:

if ($is_view == true && isset($GLOBALS['cfg']['MaxExactCountViews'])) {
    /* dirty hack to avoid performance issue with views when ['cfg']['MaxExactCount'] and ['cfg']['MaxExactCountViews'] does not help it */
    $tmp_tables = PMA_DBI_get_tables_full($db, $table);
    PMA_Table::$cache[$db][$table] = $tmp_tables[$table];
    PMA_Table::$cache[$db][$table]['ExactRows'] = $GLOBALS['cfg']['MaxExactCountViews'];
    return (int) $GLOBALS['cfg']['MaxExactCountViews']; 
}

Set $GLOBALS['cfg']['MaxExactCountViews'] value in config afterwards. phpMyAdmin now will always display this value for all VIEWS. It also will work much faster :-)

1
  • I used this hack without the conditional statement. I had the same problem with it doing select count(*) from db.table after clicking on the tables too. With 16-25M rows in innodb tables, that is a no-no. Nov 14, 2014 at 16:59
2

The way I solved your problem was by caching the output of SHOW TABLE STATUS FROM <DATABASE> into a table named f.i. showtablecache, say every 2 minutes. You can do this with some cron script for your database(s).

You could then edit the file /usr/share/phpmyadmin/libraries/database_interface.lib.php and replace the slow SHOW TABLE STATUS FROM ... with a SELECT ... FROM showtablecache WHERE ... on the new cache table.

You could also leave the phpmyadmin source alone and put a mysql-proxy instance in between that does the query rewriting for you. All you then have to do is change the $dbport variable in config-db.php :)

Using mysql-proxy for this is especially useful if you have this problem with a non-open source tool other than phpmyadmin. Like some native, maybe proprietary workbench application. (Database workbench by Upscene does something similar (if I recall correctly))


Queries for in the cron script:

START TRANSACTION;

DELETE FROM showtablecache WHERE database_ = '<DATABASE>';

INSERT INTO showtablecache
SELECT 
    '<DATABASE>'
    , TABLE_NAME
    , ENGINE
    , VERSION
    , ROW_FORMAT
    , TABLE_ROWS
    , AVG_ROW_LENGTH
    , DATA_LENGTH
    , MAX_DATA_LENGTH
    , INDEX_LENGTH
    , DATA_FREE
    , AUTO_INCREMENT
    , CREATE_TIME
    , UPDATE_TIME
    , CHECK_TIME
    , TABLE_COLLATION
    , CHECKSUM
    , CREATE_OPTIONS
    , TABLE_COMMENT
FROM
    INFORMATION_SCHEMA.TABLES
WHERE
    table_schema = '<DATABASE>';

COMMIT;

So instead of SHOW TABLE STATUS FROM <DATABASE> you use:

SELECT
    Name_ AS `Name`,
    Engine_ AS `Engine`,
    Version,
    Row_format_ AS `Row_format`,
    Rows_ AS `Rows`,
    Avg_row_length,
    Data_length,
    Max_data_length,
    Index_length,
    Data_free,
    Auto_increment_ AS `Auto_increment`,
    Create_time,
    Update_time,
    Check_time,
    Collation_ AS `Collation`,
    Checksum,
    Comment_ AS `Comment`,
    Create_options
FROM
    showtablecache
WHERE
    Database_ = <DATABASE>;

More details about this fix here: http://blog.cppse.nl/fix-slow-phpmyadmin

2

I originally used @"Andrew Kondratev" answer, without the "if view" conditional stuff, and then started looking closer at the rest of that method, and realized that was almost exactly the code that would run if $force_exact was false. I have a new, simpler hack that doesn't break quite as much and works for tables as well.

Just like with Andrew's hack:

  • Find where the installation lives, such as rpm -ql phpMyAdmin | grep Table.class.php (or your local OS equivalent).
  • EDIT: ./libraries/Table.class.php (in my case /usr/share/phpMyAdmin/libraries/Table.class.php
  • Look for static public function countRecords (line 563 in my case)
  • Insert the following at the top of that function (after the {):

            /* Tommy's Hack from http://goo.gl/HMTnLc */
            $force_exact = false;
            /* End Tommy's Hack - USE AT YOUR OWN RISK! */
    
  • In my case the "defaults" already have the following:

    config.default.php: * @global integer $cfg['MaxExactCount']
    config.default.php:$cfg['MaxExactCount'] = 0;
    config.default.php: * @global integer $cfg['MaxExactCountViews']
    config.default.php:$cfg['MaxExactCountViews'] = 0;
    
  • However, you can always add it to your config.inc.php:

    $cfg['MaxExactCountViews'] = 0;//disable trying to count the number of rows in any view
    $cfg['MaxExactCount'] = 0;//disable correcting the InnoDB estimates
    

I believe the problem is actually over in tbl_info.inc.php where it sets $force_exact to true while displaying tables. IMO, the only time that number would need to be "exact" is if you were trying to view the last page, and even then probably not.

1

For me, the problem was that xdebug profiler was on for all sites. It wrote over 40MB of logs when loading the table list in phpmyadmin. (Turning it off accelerated the load from over 15 secs to 2-3 secs).

Here are my new xdebug settings, I don't know which one did the trick:

xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1 # this still allows manual logs
xdebug.remote_autostart=0
xdebug.remote_enable=0
0

I posted a fix for a general situation where you query information_schema.tables

Slow query on information_schema.tables

0

I had this problem today with a 20 tables db, 120GB in total.

Whenever I clicked the database name in PhpMyAdmin it took forever to list tables and usually returned a web server timeout.

This hapened after I renamed database multiple times and imported and exported large amounts of data.

It felt like it tries to recalculate table statistics but failed or timed out.

Solution that worked for me:

  • I clicked table names on PhpMyAdmin left column, one by one
  • after entering each table, I clicked structure tab on top
  • scroll to bottom of structure page, under Space usage it shown inaccurate table storage usage, e.g 60KB;
  • right click and refresh structure page in browser
  • it seems to recalculate table statistics, now Space usage seems accurate, e.g 2GB;
  • after doing that for all tables, it listed tables faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.