前言
最近,我正在把我的大部分服務後端都改到 IPv6 上,不過在設定的過程中出了一點問題。即便我已經確定防火牆或是服務都已經在正常運作了,依然不會通。最後發現是 MySQL 或是 MariaDB 預設是不會監聽 IPv6 位址的,所以這篇文章就會來說說解決方式。
設定
以下內容會以 MariaDB 做解釋,與 MySQL 可能會有些差異,但不會太多。
首先我們要進入 /etc/mysql/mariadb.conf.d
資料夾。
cd /etc/mysql/mariadb.conf.d/
接著我們要編輯 50-server.cnf
這個檔案。
sudo vim 50-server.cnf
找到 [mysqld]
區塊裡,有一行是 bind-address
,他原本可能是 127.0.0.1
或是 0.0.0.0
,但這都不會監聽 IPv6,所以我們需要更新他為 *
。
[mysqld]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = *
接著存檔後重新啟動 MySQL,他就會正常監聽與工作了!
sudo systemctl restart mysql