0

I'm new into MySQL and UNIX, Actually from one UNIX box to another i connected using ssh -i commonprivatekey -p 60041 root@172.16.28.102. Once it connected then I'm executing mysql -uroot -ppassword mysql mysql prompt open i can able execute select command.

Env Details:

IP               : 172.16.28.102
SSH Port         :  60041
usernames        :  root
passwords        :  password
SSH Privatekey   :  commonprivatekey
mySQL DB Port    :  60040
mySQL DB Name    :  mysql
mySQL DB UserID  :  root
mySQL DB Password:  password

And my Java code is

try {
  Class.forName("com.mysql.jdbc.Driver");
  conn = DriverManager.getConnection("jdbc:mysql://172.16.28.102:60040/mysql", "root", "password");
}  catch (SQLException e) {
  logger.error("Could not connect to the database", e);
}

Exception trace:

Caused by: java.sql.SQLException: null,  message from server: "Unknown error 1130"
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1095)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at uk.accenture.fdt.batch.control.ConnectionsHelper.getDatabaseConnection(ConnectionsHelper.java:35)
Rajesh Narravula
  • 1,433
  • 3
  • 26
  • 54
  • Does a Database exist named on the server named "mysql"? [MYSQL URL Schema](https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html) indicates that the database you want to use in your connection is named "mysql". – Mr00Anderson Jun 01 '16 at 12:56
  • When i printed `show databases;` yes mysql also exist in that list. – Rajesh Narravula Jun 01 '16 at 12:59
  • It appears that error code is a MySQL error code related to permissions. Have you looked up `Error 1130` [Error 1130 in mysql](http://stackoverflow.com/questions/2857446/error-1130-in-mysql) – Mr00Anderson Jun 01 '16 at 13:03
  • 1
    Did you check http://stackoverflow.com/questions/19101243/error-1130-hy000-host-is-not-allowed-to-connect-to-this-mysql-server for a solution? Main point could be, that a user account is always also associated with access from where aspect (details in answer there). – Dilettant Jun 01 '16 at 13:03
  • I'm getting `ERROR 1819 (HY000): Unknown error 1819` when i execute `CREATE USER` or `GRANT ALL` commands. – Rajesh Narravula Jun 01 '16 at 13:24

2 Answers2

0

Is your application on the same server as the mysql database ? Error 1130 sounds like the user is not allowed to connect to the database. Maybe the client IP is not allowed to connect to that database. For example if you have a user root@locahost, you can only connect from the same server. So create a user that is allowed to connect from the IP. I guess that user should have the IP from the box you are trying to connect.

CREATE USER '<username>'@'<ip from the box>' IDENTIFIED BY '<password>';

You need to give him the appropriate rights of course. The following code should give him all rights. You probably don't need that.

GRANT ALL PRIVILEGES ON <database name>.* TO '<username>'@'<ip from the box>';
Norman
  • 2,351
  • 1
  • 20
  • 16
-1

i)u add a mysql connector jar file in your library folder then right click on lib->buildpath->configurebuildpath then it will show properties for input dialog box then click on library->addexternal jar->add your jar file next clickon order and support->select all the items->click ok. ii)go to ur project rightclick bulidpath->configure buildpath->ok

If those things u do rigth,u check your coloumn name in ur database.

SMS
  • 84
  • 5