• 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 打开连接慢)

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-12-05

匿名通过本文主要向大家介绍了远程连接,mysql等相关知识,希望本文的分享对您有所帮助

有次同事提出开发使用的mysql数据库连接很慢,因为我们的mysql开发数据库是单独一台机器部署的,所以认为可能是网络连接问题导致的。

在进行 ping和route后发现网络通信都是正常的,而且在mysql机器上进行本地连接发现是很快的,所以网络问题基本上被排除了。以前也遇到过一次这样的问题,可后来就不知怎么突然好了,这次又遭遇这样的问题,所以想看看是不是mysql的配置问题。在查询mysql相关文档和网络搜索后,发现了一个配置似乎可以解决这样的问题,就是在mysql的配置文件中增加如下配置参数:

在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解析是不可能完成的,从而也就明白了为什么连接那么慢了。。

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

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

  • 解析远程连接管理其他机器上的MYSQL数据库
  • 配置mysql允许远程连接的方法
  • 远程连接mysql 授权方法详解
  • 远程连接mysql数据库注意点记录
  • 远程连接mysql数据库注意事项记录(远程连接慢skip-name-resolve)
  • MYSQL不能从远程连接的一个解决方法(s not allowed to connect to this MySQL server)
  • CentOS mysql安装系统方法
  • MySQL数据库如何允许远程连接?
  • 无法远程连接mysql数据库的几个解决方法
  • 远程连接mysql数据库注意点记录

相关文章

  • 2018-12-05查看MySQL服务器线程数的方法
  • 2017-05-11centos下mysql主从同步快速设置步骤分享
  • 2017-09-08MySQL中常用命令
  • 2017-05-11MySQL ERROR 2013 (HY000)错误解决方法
  • 2018-12-05MySQL终端管理数据库操作指南
  • 2018-12-05MSSQL 清空数据库的方法
  • 2018-12-05MSSQL安全设置的具体步骤和方法小结
  • 2018-12-05Oracle 子程序参数模式,IN,OUT,NOCOPY
  • 2018-12-05远程连接局域网内的sql server 无法连接 错误与解决方法
  • 2018-12-05MySQL中存储引擎InnoDB与MyISAM的详解

文章分类

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

最近更新的内容

    • MySQL在Linux centos7环境下安装教程详解(图)
    • 关于pt-heartbeat(percona toolkit)的实例代码
    • RedHat下MySQL的基本使用方法分享
    • MySQL审计插件的测试(mcafee和mariadb版本)详情介绍
    • MySQL单表多关键字模糊查询的实现方法
    • 一个常用的报表统计SQL语句
    • Oracle 存储过程总结 二、字符串处理相关函数
    • SQL中Exists的用法实例详解
    • MYSQL的排序sql语句
    • MySQL中关于事务的具体详解

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

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