在 [mysqld] 區段加入:
bind-address = 127.0.0.1
編輯 /etc/init.d/mysql,在 start 區段的 mysqld_safe 命令加入參數:
$bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file --bind-address=127.0.0.1 &
重啟 MySQL:/etc/init.d/mysql restart。
netstat -l
tcp 0 0 localhost:mysql *:* LISTEN
僅顯示 localhost 即設定成功,外部網路無法直接連線資料庫,大幅降低暴露風險。