解决内网远程连接MySQL速度慢

前言

这里说的是mysql配置,首先排除网络问题,在网络通信良好的情况下,我们来探究mysql问题。

现象

在内网远程访问mysql特别慢

排查

因为刚刚解决了内网连接linux 速度特慢的问题,所以猜测mysql可能也会有DNS反向解析导致。

解决办法

可以在配置文件里面禁止MySQL进行反向DNS解析,
只需在my.cnf的[mysqld]段落中加入如下行:

[mysqld]
skip-name-resolve 

然后重启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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在宝塔面板上实现MySQL的远程连接,可以按照以下步骤进行操作: 1. 安装MySQL服务:在宝塔面板中,使用简单的几步即可安装MySQL服务 [1。 2. 创建数据库:在宝塔面板中,可以轻松地创建一个新的数据库 [2。 3. 安装cpolar内穿透:通过安装cpolar内穿透工具,可以实现公远程访问 [2。 4. 创建HTTP隧道映射MySQL端口:通过创建HTTP隧道映射MySQL端口,可以实现远程连接 [2。 5. 远程连接MySQL:在MySQL命令行中,使用root用户登录,并按照以下步骤进行操作 [3: - 输入以下命令以创建root用户可以从任何IP地址访问的用户: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION; - 替换'your_password'为您设定的密码。 通过这些步骤,您将能够在宝塔面板上实现MySQL的远程连接。请确保在进行远程连接之前,已经完成了必要的安全设置,如设置强密码并限制访问权限。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [宝塔面板安装配置MySQL,轻松管理数据库【公远程访问】](https://blog.csdn.net/qq_41250372/article/details/130331283)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [宝塔面板设置mysql远程登录](https://blog.csdn.net/cxh20777/article/details/130399952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值