After posting this problem when I was working, I realized that I couldnβt even ping to the EC2 or telnet server. So something basic was supposed to be wrong. Finally a friend helped me with the problem. As I expected, the problem was very specific to EC2.
Details:
When we create an instance of EC2, we get an external IP address similar to: ec2-XX-XXX-XXX-XX.ap-southeast-1.compute.amazonaws.com
When setting permissions in mysql, I granted permissions to the above IP address, i.e.:
GRANT ALL PRIVILEGES on . to worker@ 'ec2-XX-XXX-XXX-XX.ap-southeast1.compute.amazonaws.com' IDENTIFIED BY 'password';
This does not work if you are trying to contact an EC2 instance from another local EC2 instance. To do this, you need to provide the "internal IP address" of the EC2 instance, which can be found using the ip command:
ip a:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 12:31:41:02:58:47 brd ff:ff:ff:ff:ff:ff inet **XX.XX.XX.XXX/23** brd YY.YYY.YY.YYY scope global eth0 inet6 fe80::1031:41ff:fe02:5847/64 scope link valid_lft forever preferred_lft forever
For everything to work correctly, you need to provide permission for the IP address - "XX.XXX.XX.XXX/23", and it should work. Likewise, when connecting to the mysql database, the host name provided to the mysql command must also be the "internal IP address" of the host EC2 instance.
source share