连接MySql速度慢的解决方法(skip-name-resolve)

所属分类: 数据库 / Mysql 阅读数: 1066
收藏 0 赞 0 分享

最近在Linux服务器上安装MySql5后,本地使用客户端连MySql速度超慢,本地程序连接也超慢。
解决方法:在配置文件my.cnf的[mysqld]下加入skip-name-resolve。

原因是默认安装的MySql开启了DNS的反向解析。如果禁用的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。

附:How MySQL uses DNS

When a new thread connects to mysqld, mysqld will spawn a new thread to handle the request. This thread will first check if the hostname is in the hostname cache. If not the thread will call gethostbyaddr_r() and gethostbyname_r() to resolve the hostname.

If the operating system doesn't support the above thread-safe calls, the thread will lock a mutex and call gethostbyaddr() and gethostbyname() instead. Note that in this case no other thread can resolve other hostnames that is not in the hostname cache until the first thread is ready.

You can disable DNS host lookup by starting mysqld with --skip-name-resolve. In this case you can however only use IP names in the MySQL privilege tables.

If you have a very slow DNS and many hosts, you can get more performance by either disabling DNS lookup with --skip-name-resolve or by increasing the HOST_CACHE_SIZE define (default: 128) and recompile mysqld.

You can disable the hostname cache with --skip-host-cache. You can clear the hostname cache with FLUSH HOSTS or mysqladmin flush-hosts.

If you don't want to allow connections over TCP/IP, you can do this by starting mysqld with --skip-networking.

或者host中添加

192.168.1.21 N-21

更多精彩内容其他人还在看

MySQL优化之表结构优化的5大建议(数据类型选择讲的很好)

很多人都将 数据库设计范式 作为数据库表结构设计“圣经”,认为只要按照这个范式需求设计,就能让设计出来的表结构足够优化,既能保证性能优异同时还能满足扩展性要求
收藏 0 赞 0 分享

MySQL的表分区详解

这篇文章主要介绍了MySQL的表分区,例如什么是表分区、为什么要对表进行分区、表分区的4种类型详解等,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL基本命令、常用命令总结

这篇文章主要介绍了MySQL基本命令、常用命令总结,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql 强大的trim() 函数

这篇文章主要介绍了mysql 强大的trim() 函数使用方法,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL函数大全及用法示例分享

这篇文章主要介绍了MySQL的一些函数及用法示例,需要的朋友可以参考下
收藏 0 赞 0 分享

MySQL不支持INTERSECT和MINUS及其替代方法

这篇文章主要介绍了MySQL不支持INTERSECT和MINUS情况下的替代方法,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql修改数据库编码(数据库字符集)和表的字符编码的方法

Mysql数据库是一个开源的数据库,应用非常广泛。以下是修改mysql数据库的字符编码的操作过程和将表的字符编码转换成utf-8的方法,需要的朋友可以参考下
收藏 0 赞 0 分享

mysql远程登录出错的解决方法

mysql远程登录出错的情况,先比很多朋友都有遇到过吧,下面有个不错的解决方法,大家可以参考下
收藏 0 赞 0 分享

mysql通过查看跟踪日志跟踪执行的sql语句

在SQL SERVER下跟踪sql采用事件探查器,而在mysql下如何跟踪sql呢,下面有个不错的方法,大家可以参考下
收藏 0 赞 0 分享

MySQL错误代码大全

本章列出了当你用任何主机语言调用MySQL时可能出现的错误。首先列出了服务器错误消息。其次列出了客户端程序消息
收藏 0 赞 0 分享
查看更多