热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

phpmyadmin非常慢地打开MySQL表列表-phpmyadminopensMySQLtablelistsveryslowly

Icanlogintophpmyadminandseedatabasesveryquickly.OnceIclickononeofthemandtrytosee

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.

我可以登录phpmyadmin并快速查看数据库。一旦我点击其中一个并尝试查看表格列表,它就会很慢。有什么我想念的吗?在从Ubuntu 10.04更新到Ubuntu 12.04之前我没有这种情况。

6 个解决方案

#1


7  

Open \config.inc.php file and add these two line of code to it:

打开\ config.inc.php文件并将以下两行代码添加到其中:

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

And of course you can skip second line if you have not any views at the database.

如果您在数据库中没有任何视图,当然可以跳过第二行。

#2


6  

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.

这是因为你有很多行的innoDB表。 InnoDB不存储表中的行数,但MyISAM存在。因此,对于每个InnoDB表,PHPMyAdmin调用SELECT count(*)FROM query,如果行数非常高,则该查询非常慢。要解决此问题,您应该编辑config.inc.php文件并设置$ cfg ['MaxExactCount']。这将为具有较少MaxExactCount行的表调用count(*)sql。

$cfg['MaxExactCount'] = 20000;

Meaning form phpmyadmin manual

意思形式phpmyadmin手册

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.

对于InnoDB表,确定phpMyAdmin应使用SELECT COUNT获取精确行数的大表。如果SHOW TABLE STATUS返回的近似行计数小于此值,则将使用SELECT COUNT,否则将使用近似计数。

#3


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.

我最初使用@“Andrew Kondratev”的答案,没有“if view”条件的东西,然后开始仔细研究该方法的其余部分,并意识到如果$ force_exact为false,那几乎就是运行的代码。我有一个新的,更简单的黑客,它不会破坏那么多,也适用于表格。

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).
  • 查找安装所在的位置,例如rpm -ql phpMyAdmin | grep Table.class.php(或您的本地操作系统等效项)。

  • EDIT: ./libraries/Table.class.php (in my case /usr/share/phpMyAdmin/libraries/Table.class.php
  • 编辑:./ libraries/Table.class.php(在我的情况下/usr/share/phpMyAdmin/libraries/Table.class.php

  • Look for static public function countRecords (line 563 in my case)
  • 寻找静态公共函数countRecords(在我的例子中为563行)

  • 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:

    但是,您始终可以将其添加到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.

我相信问题实际上已经在tbl_info.inc.php中结束了,它在显示表时将$ force_exact设置为true。 IMO,这个数字唯一需要“精确”的时间是你试图查看最后一页,即使这样也可能没有。

#4


1  

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.

如果你有几个VIEWS有很多(> 10 ^ 5)的记录,即使MaxExactCountViews和MaxExactCount都设置为100,它的工作速度也非常慢。

Find

'static public function countRecords'

'静态公共功能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 :-)

之后在config中设置$ GLOBALS ['cfg'] ['MaxExactCountViews']值。 phpMyAdmin现在将始终为所有VIEWS显示此值。它也会更快地工作:-)

#5


1  

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

我解决问题的方法是将SHOW TABLE STATUS FROM 的输出缓存到名为f.i的表中。 showtablecache,每2分钟说一次。您可以使用数据库的某些cron脚本执行此操作。

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.

然后,您可以编辑文件/usr/share/phpmyadmin/libraries/database_interface.lib.php,并在新缓存表上使用SELECT ... FROM showtablecache WHERE ...替换慢速SHOW TABLE STATUS FROM ...。

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 :)

您也可以单独留下phpmyadmin源代码并在其间放置一个mysql代理实例,为您执行查询重写。您需要做的就是更改config-db.php中的$ dbport变量:)

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))

如果您使用phpmyadmin之外的非开源工具遇到此问题,则使用mysql-proxy非常有用。像一些原生的,也许是专有的工作台应用程序。 (Upscene的数据库工作台做了类似的事情(如果我没记错的话))


Queries for in the cron script:

在cron脚本中查询:

START TRANSACTION;

DELETE FROM showtablecache WHERE database_ = '';

INSERT INTO showtablecache
SELECT 
    ''
    , 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 = '';

COMMIT;

So instead of SHOW TABLE STATUS FROM you use:

所以不使用SHOW TABLE STATUS FROM ,而是使用:

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_ = ;

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

有关此修复的更多详细信息,请访问:http://blog.cppse.nl/fix-slow-phpmyadmin

#6


0  

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

我发布了一个修复程序,用于查询information_schema.tables的一般情况

Slow query on information_schema.tables

对information_schema.tables的查询速度慢


推荐阅读
  • JDK源码学习之HashTable(附带面试题)的学习笔记
    本文介绍了JDK源码学习之HashTable(附带面试题)的学习笔记,包括HashTable的定义、数据类型、与HashMap的关系和区别。文章提供了干货,并附带了其他相关主题的学习笔记。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文介绍了贝叶斯垃圾邮件分类的机器学习代码,代码来源于https://www.cnblogs.com/huangyc/p/10327209.html,并对代码进行了简介。朴素贝叶斯分类器训练函数包括求p(Ci)和基于词汇表的p(w|Ci)。 ... [详细]
  • 微软头条实习生分享深度学习自学指南
    本文介绍了一位微软头条实习生自学深度学习的经验分享,包括学习资源推荐、重要基础知识的学习要点等。作者强调了学好Python和数学基础的重要性,并提供了一些建议。 ... [详细]
  • 如何自行分析定位SAP BSP错误
    The“BSPtag”Imentionedintheblogtitlemeansforexamplethetagchtmlb:configCelleratorbelowwhichi ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • Nginx使用(server参数配置)
    本文介绍了Nginx的使用,重点讲解了server参数配置,包括端口号、主机名、根目录等内容。同时,还介绍了Nginx的反向代理功能。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文讲述了如何通过代码在Android中更改Recycler视图项的背景颜色。通过在onBindViewHolder方法中设置条件判断,可以实现根据条件改变背景颜色的效果。同时,还介绍了如何修改底部边框颜色以及提供了RecyclerView Fragment layout.xml和项目布局文件的示例代码。 ... [详细]
  • 本文介绍了C++中省略号类型和参数个数不确定函数参数的使用方法,并提供了一个范例。通过宏定义的方式,可以方便地处理不定参数的情况。文章中给出了具体的代码实现,并对代码进行了解释和说明。这对于需要处理不定参数的情况的程序员来说,是一个很有用的参考资料。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • Linux环境变量函数getenv、putenv、setenv和unsetenv详解
    本文详细解释了Linux中的环境变量函数getenv、putenv、setenv和unsetenv的用法和功能。通过使用这些函数,可以获取、设置和删除环境变量的值。同时给出了相应的函数原型、参数说明和返回值。通过示例代码演示了如何使用getenv函数获取环境变量的值,并打印出来。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 在开发app时,使用了butterknife后,在androidStudio打包apk时可能会遇到报错。为了解决这个问题,可以通过打开proguard-rules.pro文件进行代码混淆来解决。本文介绍了具体的混淆代码和方法。 ... [详细]
  • Vagrant虚拟化工具的安装和使用教程
    本文介绍了Vagrant虚拟化工具的安装和使用教程。首先介绍了安装virtualBox和Vagrant的步骤。然后详细说明了Vagrant的安装和使用方法,包括如何检查安装是否成功。最后介绍了下载虚拟机镜像的步骤,以及Vagrant镜像网站的相关信息。 ... [详细]
author-avatar
daadhkiw_267
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有