關於 PHP, Linux, Open Source 及個人生活記載的網誌。
RSS icon
  • 限制 MySQL 只接受 localhost 連線

    Posted on August 30th, 2007 Sam Tang 1 comment

    在預設的情況下 MySQL 接受所有連線,這個不是指 MySQL 的權限設定,而是 MySQL 有監聽它所使用的埠號。例如用 netstat 檢查會得出這個結果:

    # netstat -an | grep 3306
    tcp4 0 0 *.3306 *.* LISTEN

     
    以下是在 FreeBSD 設定只接受 localhost 連線的方法:

    1. 開啟 /etc/rc.conf

    2. 加入 mysql_args:

    mysql_enable="YES"
    mysql_args="–bind-address=127.0.0.1"

     
    3. 重新啟動 mysql

    # /usr/local/etc/rc.d/mysql-server.sh restart

     

    現在可以再用 netstat 檢查一下,可以見到 MySQL 只監聽 127.0.0.1 的 3306 埠號:

    # netstat -an | grep 3306
    tcp4 0 0 127.0.0.1.3306 *.* LISTEN

     

    One response to “限制 MySQL 只接受 localhost 連線”

    1. it is great for security

    Leave a reply

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word