zoukankan      html  css  js  c++  java
  • mysql 远程连接速度慢的解决方案

    解决方法: nvicat 链接服务器端数据库慢,可以尝试my.cnf中添加 skip-name-resolve 重启,关闭dns解析


    解决办法:

    在MySQL服务器的配置中增加一个如下配置后速度飞快。

    [mysqld]
    skip-name-resolve

    附录:( 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.

    拓展:
    [mysqld]
    skip-name-resolve 
    skip-grant-tables

    这样速度就快了!

    skip-name-resolve 

    选项就能禁用DNS解析,连接速度会快很多。不过,这样的话就不能在MySQL的授权表中使用主机名了而只能用ip格式。

    若使用–skip-grant-tables系统将对任何用户的访问不做任何访问控制,但可以用 mysqladmin flush-privileges或mysqladmin reload来开启访问控制;默认情况是show databases语句对所有用户开放,

    如果mysql服务器没有开远程帐户,就在my.ini里面加上skip-grant-tables

    附,请根据情况开放

    skip-name-resolve  一般我们只要这一项便可以 
    skip-grant-tables

  • 相关阅读:
    【BZOJ3506】[CQOI2014] 排序机械臂(Splay)
    2019年1月训练记录(1.01~1.31)
    再学点分治——动态点分治
    【洛谷5113】Sabbat of the witch(毒瘤分块)
    【洛谷1501】[国家集训队] Tree II(LCT维护懒惰标记)
    初学后缀自动机
    【洛谷3950】部落冲突(LCT维护连通性)
    【BZOJ2049】[SDOI2008] Cave 洞穴勘测(LCT维护连通性)
    LCT入门
    【BZOJ4650】[NOI2016] 优秀的拆分(后缀数组)
  • 原文地址:https://www.cnblogs.com/xiaoshahai/p/14039082.html
Copyright © 2011-2022 走看看