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.

5 Answers 5

up vote 112 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
12  
Correct. Binding is limited to either 0, 1, or all IP addresses on the server. –  Joe Sep 14 '10 at 21:01
5  
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
2  
still true as of today. –  Dennis Nolte Aug 11 at 13:07

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

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

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

You can't bind to more than one IP address, but you can bind to all available IP addresses instead. If so, just use 0.0.0.0 for a binding address in your MySQL configuration file (e.g. /etc/mysql/my.cnf) as follows:

bind-address    = 0.0.0.0

If the address is 0.0.0.0, the server accepts TCP/IP connections on all server host IPv4 interfaces.

Furthermore if the address is ::, the server accepts TCP/IP connections on all server host IPv4 and IPv6 interfaces. Use this address to permit both IPv4 and IPv6 connections on all server interfaces.

Or you can simply comment out bind-address= altogether, so it will bind to all addresses. But make sure that you don't have skip-networking enabled in your my.cnf if you want to allow remote connections as well (Read more: MySQL: Allow both remote AND local connections).

After changing the binding address, don't forget to restart your MySQL server by:

sudo service mysql restart

Eventually you can consider to run multiple instances of MySQL on a single machine (different ports) with Master/Slave replication. Replication enables data from one MySQL database server (the master) to be copied to one or more MySQL database servers (the slaves).

Read more:

share|improve this answer
    
Actually I was hoping for an option to bind to some, but not all addresses. –  BlaM Aug 12 at 17:41

protected by pauska Oct 11 at 14:23

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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