mariadb未监听TCP 3306问题解决

2020-07-22  本文已影响0人  A04

  之前通过服务器本地访问mariadb数据库的时候都没有什么问题,今天开始尝试远程登录mariadb数据库,发现登录失败;而且发现TCP三次握手,客户端发送的syn报文,服务器端都没有回应。
  登录服务器,查看端口开放情况,发现3306端口是挂在tcp6上,相当于是ipv6就可以访问到服务器的3306端口,ipv4就访问不了。

[root@server]# netstat -anplt | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      32513/mysqld  

  网上搜了一翻,一般都是因为skip-networking、或者bind-address的问题,我的mariadb版本如下,查看了/etc/my.cnf文件,都没有这两个字符串相关的行。

[root@server]# mysql -V
mysql  Ver 15.1 Distrib 10.4.6-MariaDB, for Linux (x86_64) using readline 5.1

[root@server]# vi /etc/my.cnf

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

  尝试在/etc/my.cnf文件中添加skip-networking,重启mysql进程后,发现3306就不开放了,于是把这个注释了。

[root@server]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service

  再尝试在/etc/my.cnf文件中添加bind-address=0.0.0.0,重启mysql进程后,发现3306在TCP后面的TCP6 3306的条目就消失了,这时候远程登录数据库就正常了。

[root@server]# netstat -anplt
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      548/mysqld     
上一篇下一篇

猜你喜欢

热点阅读