• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > 解决远程连接mysql很慢的方法(mysql_connect 打开连接慢)

解决远程连接mysql很慢的方法(mysql_connect 打开连接慢)

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了mysql connect,mysql real connect,mysql connect 不支持,mysql connect error,php mysql connect等相关知识,希望本文的分享对您有所帮助
在进行 ping和route后发现网络通信都是正常的,而且在mysql机器上进行本地连接发现是很快的,所以网络问题基本上被排除了。以前也遇到过一次这样的问题,可后来就不知怎么突然好了,这次又遭遇这样的问题,所以想看看是不是mysql的配置问题。在查询mysql相关文档和网络搜索后,发现了一个配置似乎可以解决这样的问题,就是在mysql的配置文件中增加如下配置参数:

[mysqld]
skip-name-resolve

      在linux下配置文件是/etc/my.cnf,在windows下配置文件是mysql安装目录下的my.ini文件。注意该配置是加在 [mysqld]下面,在更改配置并保存后,然后重启mysql并远程连接测试,一切恢复如初。该参数的官方解释信息如下:

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 lookop 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.

      根据文档说明,如果你的mysql主机查询DNS很慢或是有很多客户端主机时会导致连接很慢,由于我们的开发机器是不能够连接外网的,所以DNS解析是不可能完成的,从而也就明白了为什么连接那么慢了。同时,请注意在增加该配置参数后,mysql的授权表中的host字段就不能够使用域名而只能够使用 ip地址了,因为这是禁止了域名解析的结果。

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 解析mysql中max_connections与max_user_connections的区别
  • 解决mysql 1040错误Too many connections的方法
  • 解决远程连接mysql很慢的方法(mysql_connect 打开连接慢)
  • php 不能连接数据库 php error Can't connect to local MySQL server
  • MySQL错误ERROR 1615 解决方法
  • MySQL性能优化之max_connections配置参数浅析
  • MySQL远程连接丢失问题解决方法(Lost connection to MySQL server)
  • mysql too many open connections问题解决方法

相关文章

  • 2018-12-05Oracle新建用户、角色,授权,建表空间的sql语句
  • 2018-12-05mysql仿asp的数据库操作类
  • 2018-12-05如何在SQLSERVER中快速有条件删除海量数据
  • 2018-12-05在Oracle网络结构解决连接问题
  • 2018-12-05sqlserver2005 TSql新功能学习总结(数据类型篇)
  • 2018-12-05mysql-MySQL数据库能转换成SQLServer吗?我有一个MySQL的脚本文件怎么才能在SQLServer里操作
  • 2018-12-05SQL Server 2008R2编写脚本时智能提示功能丢失的处理方法
  • 2018-12-05MYSQL explain 执行计划
  • 2018-12-05mysql 单机数据库优化的一些实践_MySQL
  • 2018-12-05SQL Server 版本变更检查 警告

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • mysql高级联结-自然联结、外部联结使用实例
    • MySQL索引的缺点以及MySQL索引在实际操作中有哪些事项
    • mongodb管理与安全认证
    • windows下安装mysql5.7教程(图文)
    • mysql5.5 master-slave(Replication)主从配置
    • 详细介绍Mysql中的4种日志
    • mysql怎么开启远程登陆?
    • MySQL优化之InnoDB优化代码详解
    • 关于mysql 严格模式 Strict Mode的说明讲解
    • MySQL中explain的使用以及性能分析

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有