Home >Database >Mysql Tutorial >禁止Mysql默认端口访问Internet_MySQL

禁止Mysql默认端口访问Internet_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 14:05:43877browse

过去查询Mysql的时候,都见3306对所有端口开放着,感觉不安全。

netstat -anlp | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 638/mysqld
unix 2 [ ACC ] STREAM LISTENING 12305521 638/mysqld /tmp/mysql.sock

当然,也想过用Iptables来实现,不过好像还是不行。

iptables -A INPUT -p tcp -s $ANY --dport 3306 -j DROP

引用Chinaunix文章所说:

*安全配置* 为了数据的安全,可以考虑让MySQL只守候在127.0.0.1上,这样从Internet上就无法直接访问数据库了。 修改/etc/init.d/mysql文件 在start部分找到类似下面这行 $bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file &

修改成
$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

OK

而我修改/etc/init.d/mysq,找到:
把原先的

$bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file >/dev/null 2>&1 &

变为
$bindir/mysqld_safe --datadir=$datadir --pid-file=$pid_file --bind-address=127.0.0.1 &

重启mysql:/etc/init.d/mysql restart

查看后实现:natstat -l

tcp 0 0 localhost.localdo:mysql *:* LISTEN
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn