MySQL错误1042-Can't get hostname for your address解决方法[原]

在Linux上部署PHP环境并使用XAMPP时遇到MySQL无法通过其他机器访问的问题,通过修改my.cnf配置文件中的skip-name-resolve和lower_case_table_names参数解决了连接错误MySQL错误1042。

本人最近在linux上部署php环境,在利用xampp部署后有个自带的mysql,在那部机器上是可以访问的,但如果用机器外的其他mysql管理软件,连接那个机器的ip和数据库,却一直爆出:

MySQL错误1042-Can't get hostname for your address

 

后来改了linux机器上安装的mysql的配置文件

 

/opt/lampp/etc

 

里面有个my.cnf

 

打开编辑,在

[mysqld]节点下新增或修改如下两行行
skip-name-resolve #忽略主机名的方式访问
lower_case_table_names=1 #忽略数据库表名大小写

重启mysql服务,问题得到解决。

2025-10-24T06:14:45.483589Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2025-10-24T06:14:45.487190Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe (mysqld 5.7.43-log) starting as process 2792 ... 2025-10-24T06:14:45.499521Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions 2025-10-24T06:14:45.500924Z 0 [Note] InnoDB: Uses event mutexes 2025-10-24T06:14:45.501775Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier 2025-10-24T06:14:45.503093Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.13 2025-10-24T06:14:45.509869Z 0 [Note] InnoDB: Number of pools: 1 2025-10-24T06:14:45.510876Z 0 [Note] InnoDB: Not using CPU crc32 instructions 2025-10-24T06:14:45.516358Z 0 [Note] InnoDB: Initializing buffer pool, total size = 4G, instances = 8, chunk size = 128M 2025-10-24T06:14:45.739511Z 0 [Note] InnoDB: Completed initialization of buffer pool 2025-10-24T06:14:45.866688Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2025-10-24T06:14:45.917325Z 0 [Note] InnoDB: Log scan progressed past the checkpoint lsn 1818072334033 2025-10-24T06:14:45.919665Z 0 [Note] InnoDB: Doing recovery: scanned up to log sequence number 1818072343203 2025-10-24T06:14:46.501026Z 0 [Note] InnoDB: Database was not shutdown normally! 2025-10-24T06:14:46.502853Z 0 [Note] InnoDB: Starting crash recovery. 2025-10-24T06:14:53.325953Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2025-10-24T06:14:53.328050Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2025-10-24T06:14:53.331419Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2025-10-24T06:14:53.341449Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB. 2025-10-24T06:14:53.377635Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2025-10-24T06:14:53.379973Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2025-10-24T06:14:53.382232Z 0 [Note] InnoDB: Waiting for purge to start 2025-10-24T06:14:53.434201Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 7651ms. The settings might not be optimal. (flushed=0 and evicted=0, during the time.) 2025-10-24T06:14:53.434424Z 0 [Note] InnoDB: 5.7.43 started; log sequence number 1818072343203 2025-10-24T06:14:53.440369Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=3] log sequence number 1818075015616 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.440496Z 0 [Note] InnoDB: Loading buffer pool(s) from D:\MySql\data\ib_buffer_pool 2025-10-24T06:14:53.444882Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.454213Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=2] log sequence number 1818075015133 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.457121Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.459265Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=13] log sequence number 1818075023156 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.459333Z 0 [Note] Plugin 'FEDERATED' is disabled. 2025-10-24T06:14:53.461391Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=4] log sequence number 1818074852082 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.464302Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.468966Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=8883] log sequence number 1818075644951 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.469327Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.478059Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.481293Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=5] log sequence number 1818074822726 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.488992Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.493841Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=8] log sequence number 1818073611600 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.496594Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.499300Z 0 [ERROR] InnoDB: Page [page id: space=488, page number=3] log sequence number 1818075769646 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.500195Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=22] log sequence number 1818074006086 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.503793Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.505862Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.513791Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=23] log sequence number 1818074993296 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.515785Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.524243Z 0 [ERROR] InnoDB: Page [page id: space=488, page number=527] log sequence number 1818080514186 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.528019Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.537996Z 0 [ERROR] InnoDB: Page [page id: space=540, page number=7] log sequence number 1818081166468 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.541042Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.543656Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=31] log sequence number 1818075024348 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.548712Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.554624Z 0 [ERROR] InnoDB: Page [page id: space=540, page number=4] log sequence number 1818081150547 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.558427Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.565031Z 0 [ERROR] InnoDB: Page [page id: space=539, page number=4] log sequence number 1818080173025 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.567157Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=31683] log sequence number 1818075654250 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.567489Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.571042Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.598497Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2025-10-24T06:14:53.601463Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 2025-10-24T06:14:53.603981Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. 2025-10-24T06:14:53.605450Z 0 [ERROR] InnoDB: Page [page id: space=743, page number=0] log sequence number 1818074641633 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.606048Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. 2025-10-24T06:14:53.609638Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. InnoDB: Dump of the tablespace extent descriptor: len 40; hex 0000000000000000ffffffff0000ffffffff000000000002aaffffffffffffffffffffffffffffff; asc ;2025-10-24T06:14:53.618233Z 0 [ERROR] InnoDB: InnoDB is trying to free page [page id: space=743, page number=8] though it is already marked as free in the tablespace! The tablespace free space info is corrupt. You may need to dump your tables and recreate the whole database! 2025-10-24T06:14:53.622034Z 0 [ERROR] [FATAL] InnoDB: Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.624235Z 0 [Warning] CA certificate ca.pem is self signed. 2025-10-24 14:14:53 0x354c InnoDB: Assertion failure in thread 13644 in file ut0ut.cc line 921 InnoDB: We intentionally generate a memory trap. InnoDB: Submit a detailed bug report to http://bugs.mysql.com. InnoDB: If you get repeated assertion failures or crashes, even InnoDB: immediately after the mysqld startup, there may be InnoDB: corruption in the InnoDB tablespace. Please refer to InnoDB: http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html InnoDB: about forcing recovery. 2025-10-24T06:14:53.625645Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2025-10-24T06:14:53.628676Z 0 [Note] Server hostname (bind-address): '*'; port: 3308 2025-10-24T06:14:53.629979Z 0 [Note] IPv6 is available. 2025-10-24T06:14:53.630668Z 0 [Note] - '::' resolves to '::'; 2025-10-24T06:14:53.632389Z 0 [Note] Server socket created on IP: '::'. 2025-10-24T06:14:53.747077Z 0 [ERROR] InnoDB: Page [page id: space=26, page number=16384] log sequence number 1818075741603 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:53.751073Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:53.924848Z 0 [Note] Failed to start slave threads for channel '' 2025-10-24T06:14:54.002381Z 0 [Note] Event Scheduler: Loaded 0 events 2025-10-24T06:14:54.003266Z 0 [Note] C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe: ready for connections. Version: '5.7.43-log' socket: '' port: 3308 MySQL Community Server (GPL) 2025-10-24T06:14:54.063857Z 0 [ERROR] InnoDB: Page [page id: space=28, page number=0] log sequence number 1818073721575 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.067646Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.073181Z 0 [ERROR] InnoDB: Page [page id: space=28, page number=4] log sequence number 1818073721575 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.076879Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.081031Z 0 [ERROR] InnoDB: Page [page id: space=28, page number=5] log sequence number 1818073639109 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.083439Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.087366Z 0 [ERROR] InnoDB: Page [page id: space=488, page number=0] log sequence number 1818074963526 is in the future! Current system log sequence number 1818072347793. 2025-10-24T06:14:54.089008Z 0 [ERROR] InnoDB: Your database may be corrupt or you may have copied the InnoDB tablespace but not the InnoDB log files. Please refer to http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html for information about forcing recovery. 2025-10-24T06:14:54.840960Z 0 [Note] InnoDB: Buffer pool(s) load completed at 251024 14:14:54
最新发布
10-25
### 解决方案 对于无法连接到本地 MySQL 服务器并显示 `error 10061` 的情况,通常意味着客户端尝试建立连接时目标计算机积极拒绝了该请求。这可能是因为 MySQL 服务未启动、配置文件设置不正确或其他网络相关问题。 #### 检查 MySQL 服务状态 确认 MySQL 是否正在运行非常重要。如果服务停止,则任何外部应用程序都无法与其通信。可以通过命令行工具来验证这一点: ```bash net start | findstr /C:mysql ``` 这条指令会列出所有已启动的服务中的 MySQL 实例名称[^1]。 #### 配置防火墙规则 有时 Windows 或其他第三方软件安装的个人防火墙可能会阻止来自特定程序或端口的数据流。确保允许通过 MySQL 使用的默认端口(通常是3306),除非自定义设置了不同的监听端口号[^2]。 #### 修改 my.ini/my.cnf 文件 检查 MySQL 安装目录下的配置文件 (`my.ini` 或者 Linux 下为 `my.cnf`) 中有关绑定地址(bind-address) 和端口(port) 的设定是否恰当。例如: ```ini [mysqld] port=3306 bind-address=127.0.0.1 ``` 上述配置使得 MySQL 只接受来自本机(`localhost`, 即 `127.0.0.1`) 上的应用程序发起的 TCP/IP 连接请求;如果不是这种情况,请调整 bind-address 参数以便适应实际需求[^3]。 #### 增加最大连接数限制 当大量并发连接耗尽资源时也会引发此类错误。可以适当增加 max_connections 参数值以应对更高的负载量级。编辑配置文件加入如下内容后重启数据库引擎生效: ```ini max_connections = 500 ``` #### 排除端口冲突可能性 尽管提到的情况表明端口并未被占用,但仍建议排查是否有其他进程意外绑定了相同的端口。使用 netstat 工具可以帮助识别潜在的竞争状况: ```powershell Get-Process -Id (Get-NetTCPConnection | Where-Object LocalPort -eq 6033).OwningProcess ``` 以上 PowerShell 脚本能够返回占用指定端口的进程 ID 及其相关信息。 #### 日志分析 最后但同样重要的是查看 MySQL 错误日志文件,其中往往包含了更多关于为什么会出现这些症状的具体线索。路径一般位于数据存储位置附近,默认情况下可能是这样的形式:`<datadir>\hostname.err`[^4]。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值