Shvilam
Shvilam

Reputation: 236

how to add a port to mysql server

I want to add to MySql another tcp port that I can connect to that port from my application

I have a duplicate of my application and I'm running them both from the same machine. They both are connected to the MySql server that are running on the same machine. The problem is that the default port 3306 is already taken.

Upvotes: 4

Views: 20706

Answers (3)

altuzar
altuzar

Reputation: 472

You can do that with something like this:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 9005 -j REDIRECT --to-port 9000

Where eth0 is your network dev, 9005 is your "source port", and 9000 the port where your service is running. Oh, that example is for TCP protocol only.

You can find more examples about port redirection here. Useful site for Linux, btw.

Upvotes: 8

zombat
zombat

Reputation: 94157

You cannot bind mysqld to listen to multiple ports. The only way you can achieve this is with internal routing rules which would forward the target port to 3306.

If you are on linux, you can achieve this using iptables. iptables is a bundle of fun normally reserved for system administrators though.

Is there a reason why both copies of your application can't connect to the same port 3306? Normally you should be able to have any number of clients connecting.

Upvotes: 6

Journeyman Programmer
Journeyman Programmer

Reputation: 1366

A single mysql instance can host multiple databases. So an alternative for you is that each application connects to the same mysql instance running at port 3306, but each uses a different database name.

Upvotes: 1

Related Questions