首页 > 技术文章 > MySQL 执行 'use databases;' 时很慢

wangxiaoqiangs 2016-09-01 16:58 原文


问题描述:

  就是这么个情况,登录数据库切换库时感觉很卡,需要等待几秒钟。

案例:

shell > mysql -uroot -ppassword

mysql> use databases;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql>

# 当数据库中表比较多,且单表又比较大时,执行这个 use databases 指令就会很卡 ( 也跟机器性能有很大关系 )

解决方法:

# 这时就可以按照提示,连接时加入 -A 参数

shell > mysql -A -uroot -ppassword

mysql> use databases;
Database changed

# 这样就很快了,简直快的飞起。

参数解释:

-A, --no-auto-rehash 
        No automatic rehashing. One has to use 'rehash' to get
        table and field completion. This gives a quicker start of
        mysql and disables rehashing on reconnect.

 

推荐阅读