how to add a port to mysql server - mysql

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.

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.

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.

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.

Related

what is the port 33060 for mysql server ports in addition to the port 3306

background purpose: I want to restrict inbound connection to MYSQL server only for specific host by setting inbound rules of windows firewall.
MYSQL server port is open on 3306.
However, when I open firewall setting, I can see two ports are opened on 3306 and 33060 as follows:
what is that? Should I restrict 33060 as well?
The port for X Protocol (mysqlx_port), supported by clients such as MySQL Shell, MySQL Connectors and MySQL Router, is calculated by multiplying the port used for classic MySQL protocol by 10. For example if the classic MySQL protocol port is the default value of 3306 then the X Protocol port is 33060.
See MySQL Port Reference Tables for more information.
The MySQL X service, is listening on all interfaces, by default over localhost, on TCP port 33060 and clients can connect to it through x protocol. So you need to restrict it for specific host to ban it to connect through x protocol. I suggest use it just for localhost.
You can see open ports by mysql through the following command:
sudo lsof -i -P -n | grep 3306

IPTables Remote mySQL Rule

I have a magento web (192.168.148.151) and remote mysql (192.168.140.147) box that im trying to create a rule so that the frontend will talk to the mySQL db
Im using IPTables (ubutun 16.04) Linode
When I disable IPTables I can telnet to the mysql box fine.
Magento runs fine also.
I would like to enable some rules in IP Tables on the Web Server so only the bare min ports like 80,443,22 are open
On the Web Server, with ip tables disabled I can telnet to the mySQL box
For example:
telnet 192.168.140.147 3306
When I however turn on IPTables my rule doesnt work
Here is my rule
-A INPUT -p tcp --dport 3306 -s 192.168.148.151 -d 192.168.140.147 -j ACCEPT
How can I communicate from IP:192.168.148.151 to mySQL on IP: 192.168.148.151 using an rule in IPTables?
Regards
Brendan

Database Not connectable through Public IP

NOTE. operation system is ubuntu 14.*
I am breaking my head over my connection on my MYSQL server. I try to connect to my MYSQL server internal through my public ip. But i am unable to connect. While i am able to connect when i connect to localhost and when i connect externally.
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
I commented the bind-adress out and this should bind the addres to 0.0.0.0. I also tried to setup the bind-adres to 0.0.0.0. This also doesnt work.
My hosts file is setup up as follows:
127.0.0.1 MY-IP
When i telnet on port 80 to my public ip there is no problem.
telnet MY-IP 80
I get:
Trying MY-IP...
Connected to MY-IP.
Escape character is '^]'.
But when i try this on port 3306 it keeps on:
Trying MY-IP...
I also granted all the right permissions to my MYSQL users. And i am possible to connect externaly and internaly. But it is not possible for me to connect internaly with my public ip.
Also i tried to find a solution with netstat.
netstat -tln
give mes
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
EDIT: Just disabled UFW. It still doesnt work.
ufw status
Status: inactive
EDIT2: Is it possible that mysql is ignoring the /etc/hosts file?
Could somebody help me a bit further with some great ideas where the problem might be.
You should change the bind address to 0.0.0.0 then restart the mysqld. Also make sure there is no firewall enabled:
iptables -n -L
if there are rules, blocking port 3306, delete them, or just disable the firwall with
iptables -F
also use netstat to check if the server is listening on the external ip:
netstat -tupan |grep :3306

Firewall settings in linux for remote mysql

I am trying to connect a remote mysql database in my local application. But it was not connecting with the given user name and password. Though I gave the GRANT ALL to that user. After a long study I came to know about firewall. I assume the following rules of firewall is the culprit for not connecting:
REJECT tcp -- anywhere anywhere tcp dpt:mysql reject-with icmp-port-unreachable
Please let me know if I am right. And please suggest me a solution to overcome this.
You can poke a hole in your firewall, to your given IP address by running the following (as root)
iptables -I INPUT -p tcp --dport 3306 --src 103.19.252/24 -j ACCEPT
-I INPUT signifies we are looking at incoming traffic
--dport 3306 means any traffic headed for port 3306 (mysql)
--src 103.19.252/24 will open up the connection to any traffic that originates from the 103.19.252.xx subnet
-j ACCEPT means let it through
You'll also need to make sure your MySQL user is allowed to connect from that ip

How do I forward from one local port to another local port on OS X?

I have a MySQL instance running locally on port 3306, but for some legacy apps I also want to make it available on port 3305 (don't ask). Is there an easy way to do this on OS X, so that if I try to connect on either 3305 or 3306 they will both go to the MySQL server on 3306?
You can use ipfw to set up a forwarding rule for port 3305 to send it to port 3306.
ipfw add fwd localhost,3306 tcp from any to any 3305 via en0
My syntax might be a little off and you may have to change it to the actual IP address or add a second rule for it.