Skip to main content

How to Connect mysql through JDBC connector through Tomcat or externally.

Solution:

This can happen for a variety of reasons. I just saw it myself a few weeks ago but I can't remember what the fix was for me.
1) Verify the address mysql is bound to, it's probably 127.0.0.1 (only) which I believe is the default (at least on standard Ubuntu server). You'll have to comment out the bind-address parameter in my.cnf to bind to all available addresses (you can't choose multiple, it's one or all).
2) If it is bound to 127.0.0.1 and you can't connect using "localhost", make sure it's not resolving to the IPv6 localhost address instead of IPv4. (or just use the IP address)
3) Double and triple-check the port that mysql is listening on.
4) Make sure you're using the right JDBC connector for your JDK.
5) Make sure you're not doing something really silly like starting mysql with --skip-networking.

Comments

Popular posts from this blog

How to access metadata in MySql from Java application (User does not have access to metadata ,SQLException)

When you get an error message like: java.lang.Exception: java.sql.SQLException: User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with "noAccessToProcedureBodies=true" to have driver generate parameters that represent INOUT strings irregardless of actual parameter types. Ans: Please use the below connection string settings:  private Connection con;  String connectionURL = "jdbc:mysql://<ip address>:3306/<database name>?user=<username>&password=<password>&noAccessToProcedureBodies=true"; con = DriverManager.getConnection(connectionURL);

Connecting to MySql Server Remotely

When you get an error message like this: javax.security.sasl.AuthenticationException:  Database Error: java.sql.SQLException: null,  message from server: "Host 'xx.xx.xx.xx' is not allowed to connect to this MySQL server" It show that you are not configured the MySql Server correctly. To configure a MySql Server for accessing remotely you need to grant permission for the client in the Server. Here is the Linux command line codes: root@server:~#  mysql -u<username> -p<password>       - log in to MySql > grant all on cheque_alert.* to '<user>'@'<IP address of remote system>'; This will grant all permission to the client machine from the IP:xxx.xxx.xx.xxx To view the permission for any client: > SHOW GRANTS FOR '<user>'@'xxx.xxx.xx.xxx';   eg.: SHOW GRANTS FOR 'root'@'11.111.105.111'; To remove the Grant/permission :  > DROP USER '<user>'@'xxx.xxx.xx