MySQL Table with Unique Servers and multiple ports

I’m creating a master server list. So basically any time one of my servers goes online, it gets posted to the master server list.

Every server has a unique IP address obviously, however there can be multiple servers per IP address (if the server on the same IP uses a different tcp port and udp port).

So the table has 3 columns: ip (TEXT), tcp_port (INT), udp_port (INT)

For example:

  • 45.29.10.11 hosts a server using TCP port 500 and UDP port 600.
  • 45.29.10.11 hosts another server using TCP port 501 and UDP port 601.
  • 45.29.10.11 hosts yet another server using TCP port 502 and UDP port 602.

And so forth. How do I make it so the master server can add multiple servers to the list with the same IP but they must have different ports, having the tcp_port not exist in any other rows and the udp_port not exist in any other rows either.

Do I just need to add these columns: ip, tcp_port, udp_port to the unique_index and that should be it?

What’s the correct table creation and insert syntax for this?


Source: syntax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.