[MySQL FAQ]系列 -- MySQL支持绑定到多个ip上吗

不能,只能用 bind-address 参数设定要绑定的某个ip,或者不设置它,直接帮定到所有ip上;或者,可以用 skip-networking 选项,直接取消网络监听,只保留本机的socket连接。

技术相关:

评论

这篇文章有误,mysql是可以绑定多个IP的, 只需添加多行bind-address即可.

我测试过了,是可以指定多行,但是只有最后一个生效(mysql 5.0.45),你确信你测试过?

MySQL方案、培训、支持

可以的,我一直在使用这种方法呀. 我的版本是5.0.41-log. 我看了另一台服务器是mysql 5.0.41的,也是可以.

麻烦贴下你的配置,还有 netstat -na 的结果

MySQL方案、培训、支持

公网地址处理了一下.

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:672 0.0.0.0:* LISTEN
tcp 0 0 192.168.5.4:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 192.168.5.4:3306 192.168.5.20:47630 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:46607 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45828 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45063 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:46386 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:48165 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:48166 ESTABLISHED
tcp 0 0 192.168.5.4:44153 192.168.5.3:3306 ESTABLISHED
tcp 0 0 192.168.5.4:3306 192.168.5.20:47680 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45695 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:46953 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:47205 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:48031 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45453 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:47794 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45991 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:47313 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:48068 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45055 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:46840 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:46072 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45301 TIME_WAIT
tcp 0 0 192.168.5.4:3306 192.168.5.20:45811 TIME_WAIT
tcp 0 0 :::45622 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 ::ffff:218.240.1.1:45622 ::ffff:211.147.10.22:13398 ESTABLISHED
udp 0 0 0.0.0.0:32768 0.0.0.0:*
udp 0 0 0.0.0.0:666 0.0.0.0:*
udp 0 0 0.0.0.0:669 0.0.0.0:*
udp 0 0 0.0.0.0:161 0.0.0.0:*
udp 0 0 0.0.0.0:5353 0.0.0.0:*
udp 0 0 0.0.0.0:111 0.0.0.0:*
udp 0 0 0.0.0.0:631 0.0.0.0:*
udp 0 0 :::32769 :::*
udp 0 0 :::5353 :::*
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ACC ] STREAM LISTENING 13752 /tmp/mysql.sock
unix 2 [ ACC ] STREAM LISTENING 42919964 /tmp/ssh-CGuWng9661/agent.9661
unix 2 [ ACC ] STREAM LISTENING 39570120 /var/run/cups/cups.sock
unix 2 [ ACC ] STREAM LISTENING 8105 /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 7955 /dev/gpmctl
unix 15 [ ] DGRAM 6947 /dev/log
unix 2 [ ACC ] STREAM LISTENING 7236 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 7297 /var/run/sdp
unix 2 [ ACC ] STREAM LISTENING 7372 /var/run/pcscd.comm
unix 2 [ ACC ] STREAM LISTENING 7512 /var/run/acpid.socket
unix 2 [ ] DGRAM 1954 @/org/kernel/udev/udevd
unix 2 [ ACC ] STREAM LISTENING 8015 /tmp/.font-unix/fs7100
unix 2 [ ] DGRAM 8145 @/org/freedesktop/hal/udev_event
unix 2 [ ACC ] STREAM LISTENING 8136 @/var/run/hald/dbus-52pP5mfID2
unix 2 [ ACC ] STREAM LISTENING 8137 @/var/run/hald/dbus-nhMyE3sdLE
unix 3 [ ] STREAM CONNECTED 9630 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 9629
unix 3 [ ] STREAM CONNECTED 9346 /var/run/acpid.socket
unix 3 [ ] STREAM CONNECTED 9345
unix 3 [ ] STREAM CONNECTED 9338 @/var/run/hald/dbus-52pP5mfID2
unix 3 [ ] STREAM CONNECTED 9335
unix 3 [ ] STREAM CONNECTED 8140 @/var/run/hald/dbus-nhMyE3sdLE
unix 3 [ ] STREAM CONNECTED 8139
unix 3 [ ] STREAM CONNECTED 8107 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 8106
unix 3 [ ] STREAM CONNECTED 8102
unix 3 [ ] STREAM CONNECTED 8101
unix 2 [ ] DGRAM 8100
unix 2 [ ] DGRAM 7952
unix 2 [ ] DGRAM 7931
unix 2 [ ] DGRAM 7912
unix 2 [ ] DGRAM 7840
unix 2 [ ] DGRAM 7534
unix 2 [ ] DGRAM 7479
unix 2 [ ] DGRAM 7392
unix 2 [ ] DGRAM 7365
unix 3 [ ] STREAM CONNECTED 7283 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 7282
unix 2 [ ] DGRAM 7266
unix 2 [ ] DGRAM 7257
unix 3 [ ] STREAM CONNECTED 7238
unix 3 [ ] STREAM CONNECTED 7237
unix 3 [ ] STREAM CONNECTED 7201
unix 3 [ ] STREAM CONNECTED 7200
unix 2 [ ] DGRAM 7053
unix 2 [ ] DGRAM 6957

你如何配置的?公网地址用abc代替就行了。

MySQL方案、培训、支持

只贴出mysqld部分. 我没有监听公网地址.
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir=/home/server/mysql
datadir=/data/mysqldata
skip-locking
skip-name-resolve
#skip-slave-start
key_buffer = 2048M
max_allowed_packet = 16M
query_cache_size=16777216
table_cache = 512
sort_buffer_size = 4096K
net_buffer_length = 8K
read_buffer_size = 4096K
read_rnd_buffer_size = 16M
myisam_sort_buffer_size = 64M
thread_concurrency = 8
default-character-set=utf8
default-collation=utf8_general_ci

thread_cache_size=16

max-connections=1500

bind-address=127.0.0.1
bind-address=192.168.5.4

嗯,但是没看到你的 netstat 结果中有监听了 127.0.0.1:3306 啊?

MySQL方案、培训、支持

顺便说一下我的服务器是centos4.X系列的.