??之前通過服務(wù)器本地訪問mariadb數(shù)據(jù)庫的時候都沒有什么問題,今天開始嘗試遠程登錄mariadb數(shù)據(jù)庫,發(fā)現(xiàn)登錄失敗;而且發(fā)現(xiàn)TCP三次握手,客戶端發(fā)送的syn報文,服務(wù)器端都沒有回應(yīng)。
??登錄服務(wù)器,查看端口開放情況,發(fā)現(xiàn)3306端口是掛在tcp6上,相當(dāng)于是ipv6就可以訪問到服務(wù)器的3306端口,ipv4就訪問不了。
[root@server]# netstat -anplt | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 32513/mysqld
??網(wǎng)上搜了一翻,一般都是因為skip-networking、或者bind-address的問題,我的mariadb版本如下,查看了/etc/my.cnf文件,都沒有這兩個字符串相關(guān)的行。
[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進程后,發(fā)現(xiàn)3306就不開放了,于是把這個注釋了。
[root@server]# service mysql restart
Redirecting to /bin/systemctl restart mysql.service
??再嘗試在/etc/my.cnf文件中添加bind-address=0.0.0.0,重啟mysql進程后,發(fā)現(xiàn)3306在TCP后面的TCP6 3306的條目就消失了,這時候遠程登錄數(shù)據(jù)庫就正常了。
[root@server]# netstat -anplt
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 548/mysqld