The date of the sor is not connected to the bd: Connection refused: connect mysql



  • I can't access the database sales using javax.sql.DataSource, error:

    java.net.ConnectException: Connection refused: connect mysql

    When using mysql workbench, the connection is happening. That's where I use ssh connection. How do you do it on a dater, too?

    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://255.255.255.255:3306/some_db");
        dataSource.setUsername("xxx");
        dataSource.setPassword("yyy");
        return dataSource;
    }
    

    The same configuration works for a local H2 bd.



  • Access to the database is probably only local. In order to be remotely connected to the base, we need to get SSL a tunnel to the server. Two ways:

    1. Throw out the tunnel from the terminal:

      ssh -L 33066:127.0.0.1:3306 user@255.255.255.255
      

      In Java, connect:

      dataSource.setUrl("jdbc:mysql://127.0.0.1:33066/some_db");
      
    2. Throw a tunnel out of Java. More detailed http://cryptofreek.org/2012/06/06/howto-jdbc-over-an-ssh-tunnel/ ♪



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2