MySQL初始安装登录:ERROR 2003 (HY000): Can‘t connect to MySQL server on

安装环境:

bash 复制代码
[root@localhost ~]# hostnamectl
   Static hostname: (unset)
Transient hostname: localhost
         Icon name: computer-vm
           Chassis: vm 🖴
        Machine ID: 1d71fe6ef4c74a1684adcdaa8b7d4823
           Boot ID: bf812fd7a4374a74b891c8c55a6ebd1b
    Virtualization: vmware
  Operating System: CentOS Stream 9
       CPE OS Name: cpe:/o:centos:centos:9
            Kernel: Linux 5.14.0-527.el9.aarch64
      Architecture: arm64
   Hardware Vendor: VMware, Inc.
    Hardware Model: VMware20,1
  Firmware Version: VMW201.00V.24006586.BA64.2406042154
[root@localhost ~]#

MySQL版本:

bash 复制代码
[root@localhost ~]# mysql --version
mysql  Ver 8.0.36 for Linux on aarch64 (Source distribution)

安装完毕,远程登录报错:

bash 复制代码
➜  ~ mysql -h 192.168.86.129  -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.86.129:3306' (61)

排查

1、开放端口
bash 复制代码
[root@localhost ~]# firewall-cmd --zone=public --permanent --add-port=3306/tcp
success
2、检查MySQL服务
bash 复制代码
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
     Active: active (running) since Sun 2024-12-29 19:55:39 CST; 1h 24min ago
   Main PID: 36797 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 10104)
     Memory: 399.1M
        CPU: 51.468s
     CGroup: /system.slice/mysqld.service
             └─36797 /usr/libexec/mysqld --basedir=/usr
3、检查MySQL用户是否允许远程访问
bash 复制代码
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT user, host FROM mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

如果都为localhost,则根据规则设置允许远程访问

bash 复制代码
mysql> UPDATE mysql.user SET host = '%' WHERE user = 'root' AND host = 'localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

设置完毕,此时再次尝试远程连接

bash 复制代码
➜  ~ mysql -h 192.168.86.129  -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.36 Source distribution

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit;
Bye
相关推荐
Mr.Daozhi37 分钟前
RAG 进阶实战:跑通 Demo 后我连续翻了 6 次车,逐一修复才真正可用(含 Gradio Web 版)
前端·数据库·langchain·大模型·gradio·rag·科研工具
小程故事多_8043 分钟前
Claude Code自定义workflow skills用法
数据库·人工智能·智能体
大鹏说大话43 分钟前
SQL 排序与分组实战:解决“分组后取最新数据“
android·java·数据库
quan26311 小时前
20260529,日常开发-数据库主从问题
java·mysql·主从·延迟
夏贰四1 小时前
数据建模工具如何筑牢数据根基?数据建模工具怎样落实标准体系?
数据库·数学建模·数据建模工具
程序猿阿伟3 小时前
《一套完整方法论:搞定图形应用的Docker镜像优化》
数据库·docker·容器
二等饼干~za8986683 小时前
geo优化源码开发搭建技术分享
大数据·网络·数据库·人工智能·音视频
数据库小学妹3 小时前
HTAP混合负载架构:如何用一个数据库同时搞定交易和分析
数据库·经验分享·架构·dba
wuxinyan1233 小时前
工业级大模型学习之路029:解决双智能体调用数据库报错问题
数据库·人工智能·python·学习·智能体
Elastic 中国社区官方博客3 小时前
Elastic 线下 Meetup 将于 2026 年 7 月 26 号下午在深圳举行
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索