解决:连接MySQL的10060错误:Can‘t connect to MySQL server on ‘*.*.*.*‘(10060)
Posted 小企鹅推雪球!
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决:连接MySQL的10060错误:Can‘t connect to MySQL server on ‘*.*.*.*‘(10060)相关的知识,希望对你有一定的参考价值。
文章目录
问题描述
-
第一步:检查网络配置呗,能不能ping上客户机。(跳过)
-
第二步:客户机上的mysql没启动:
systemctl status mysqld
[root@localhost mysql]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 四 2022-10-13 06:01:00 UTC; 41min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 10500 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 10479 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 10503 (mysqld) Tasks: 28 CGroup: /system.slice/mysqld.service └─10503 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 10月 13 06:01:00 localhost.localdomain systemd[1]: Stopped MySQL Server. 10月 13 06:01:00 localhost.localdomain systemd[1]: Starting MySQL Server... 10月 13 06:01:00 localhost.localdomain systemd[1]: Started MySQL Server.
-
第三步:防火墙上的3306端口没开放,查一下:
ss -lnt
[root@localhost mysql]# ss -lnt State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 128 *:6000 *:* LISTEN 0 5 192.168.122.1:53 *:* LISTEN 0 128 *:22 *:* LISTEN 0 128 127.0.0.1:631 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 80 :::3306 :::* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::6000 :::* LISTEN 0 128 :::22 :::* LISTEN 0 128 ::1:631 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::*
-
3306端口开了,但是3306端口没有被监听!(我的问题就是这),所以,先添加需要监听的端口:
[root@localhost mysql]# firewall-cmd --permanent --zone=public --add-port=3306/tcp Warning: ALREADY_ENABLED: 3306:tcp success [root@localhost mysql]# firewall-cmd --permanent --zone=public --add-port=3306/tcp Warning: ALREADY_ENABLED: 3306:tcp success
-
加了3306端口之后可以测一下了,如果显示不允许连接,那么开启mysql ,使用root登录,进入mysql数据库,查询mysql.user这张表,可以看到HOST,是localhost,表示只能本地登录mysql,
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select User,HOST from mysql.user; +---------------+-----------+ | User | HOST | +---------------+-----------+ | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 3 rows in set (0.00 sec)
-
增加远程访问权限,%百分号表示允许任何IP访问数据库,并刷新:
flush privileges;
,再重启下mysql数据库,接下来就可以正常登录了mysql> grant all privileges on *.* to root@"%" identified by "1234566"; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> select User,HOST from mysql.user; +---------------+-----------+ | User | HOST | +---------------+-----------+ | root | % | | mysql.session | localhost | | mysql.sys | localhost | | root | localhost | +---------------+-----------+ 4 rows in set (0.00 sec) mysql> systemctl restart mysqld
以上是关于解决:连接MySQL的10060错误:Can‘t connect to MySQL server on ‘*.*.*.*‘(10060)的主要内容,如果未能解决你的问题,请参考以下文章
远程连接MySQL错误:Can't connect to MySQL server (10060)
MySQL错误2003:Can't connect to MySQL server (10060)
MySQL错误2003:Can't connect to MySQL server (10060)
Can't connect to MySQL server (10060)
连接mysql数据库时提示2003 can't connect to MySQL server on ip(10060)的解决办法
客户端不能连接MySQL - 2003-Can't connect to MySQL server on '192.168.43.180'(10060 "Unknow