Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a secret way to bind MySQL to more than one IP address?

As far as I can see the bind-address parameter in the my.cnf does not support more than one IP and you can't have it more than once.

share|improve this question

migrated from stackoverflow.com May 6 '10 at 19:25

This question came from our site for professional and enthusiast programmers.

add comment

9 Answers

up vote 100 down vote accepted

No, there isn't (I just checked 1 hour ago). You can comment the bind-address in my.cnf:

#skip-networking
#bind-address                   = 127.0.0.1

If you want only 2 IPs, you will then have to use a firewall.

share|improve this answer
11  
Correct. Binding is limited to either 0, 1, or all IP addresses on the server. –  Joe Sep 14 '10 at 21:01
3  
Note, however, than you can publish and serve both a local unix socket and a network socket by specifying both the socket and bind-address options. –  danorton Mar 30 '12 at 17:04
add comment

Binding to 127.0.0.x won't make it available to all the devices, it will make it available locally only. If you wish to make it available to all the interfaces, you should use 0.0.0.0. If you wish to access it from more than one, but less than all the interfaces, you should bind to 0.0.0.0 and firewall off the interfaces you don't want to be accessed through.

Also, as a second layer of security, you should make sure that all your MySQL users have host field set to something other than % (ie any host).

share|improve this answer
1  
Unless you have a broken network stack you cannot bind a TCP port to address 0.0.0.0. –  John Gardeniers May 6 '10 at 22:49
15  
You can bind to 0.0.0.0. You just can't route to it. If you're on Linux (or even on Windows, just install netcat for windows) try: in one terminal: nc -l 0.0.0.0 4321 and in a second terminal: telnet <IP of any interface your computer has> 4321 And it will connect to it. –  Cd-MaN May 18 '10 at 16:49
    
As I said, unless you have a broken network stack... –  John Gardeniers Jun 25 '10 at 2:58
    
@JohnGardeniers Is that why it's in the linux ip(7) man page defined under special addresses: INADDR_ANY (0.0.0.0) means any address for binding;? –  ebyrob Jul 24 '13 at 17:06
    
On Debian, create a file /etc/mysql/conf.d/bindaddress.cnf file with content [mysqld] \n bind-address = 0.0.0.0 –  Yves Martin Aug 16 '13 at 12:07
add comment

No, you cannot. The page you link to clearly states:

The IP address to bind to. Only one address can be selected. If this option is specified multiple times, the last address given is used.

If no address or 0.0.0.0 is specified, the server listens on all interfaces.

share|improve this answer
add comment

I think your question is related to this bug http://bugs.mysql.com/bug.php?id=14979 The bug report suggest some workaround.

share|improve this answer
    
A MySQL feature request dating back from 2005! –  Tonin Apr 24 at 14:02
add comment

You're mistaken. Like Highlanders, there can be only one.

share|improve this answer
add comment

You cannot have two "bind-address" lines. No error messages, but only last line is used. You can verify this by checking active mysqld ports with "netstat -anp | grep mysql".

I quess that's why negative points to Zebastian.

share|improve this answer
add comment

Colic:

You can specify a range as well: http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_bind-address


I do not see any reference to specifying a range at the link you provided.

share|improve this answer
add comment

It's also possible to have two lines with bind-address xxx.xxx.xxx.xxx with two different ip's.

share|improve this answer
    
This works very well. Why negative points? –  Anonymous Apr 9 '10 at 9:52
3  
From the manual: "Only one address can be selected. If this option is specified multiple times, the last address given is used." (dev.mysql.com/doc/refman/5.1/en/…) –  richsage Dec 19 '10 at 9:53
1  
Zebastian is correct, you can have two lines, but it won't meet the needs of the original requester. –  Robert Novak Aug 7 '11 at 0:09
    
Should probably simply remove this misleading answer! : D –  Kzqai May 20 at 18:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.