Search code examples
mysqltomcatamazon-ec2connector-j

Unable to connect to MySQL from Java Servlet in Amazon EC2


I recently deployed a .war from Netbeans IDE on my local machine to Amazon EC2. The Servlet in my Webapp used JBDC Connector/J, the jar file for which was copied into Libraries in Netbeans. The WebApp was working well on my local machine. But the logs of Tomcat on Amazon EC2 shows an error the host 'xyz' is not allowed to connect to this MySQL Server.


Solution

  • confirm host information for mysql - run this on mysql:

    select host, user from mysql.user;
    

    If your host/port information is correct, try checking privileges being used for the web application. Also, make sure that your database server is able to bind on the specified port (netstat -an | grep 'port number') & that the client app can connect to that port (on the host). hope it helps