sql >> Base de Datos >  >> RDS >> Mysql

Azure:permiso denegado al intentar conectarse a una base de datos MySQL externa

Me cansé de reproducir tu problema pero fallé.

Aquí, traté de crear un java spring-boot proyecto para probar la conexión con Azure MySQL Database .

Fragmento de mi código:

    private static String hostName = "<your host name>";
    private static String dbName = "sys";
    private static String user = "<user name>";
    private static String password = "password";
    private static String portNumber = "3306";

    @RequestMapping("/hello")
    public String index() throws SQLException {
        Connection conn = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e1) {
            e1.printStackTrace();
        }
        try {
            String url = "jdbc:mysql://"+hostName+":"+portNumber+"/"+dbName+"?verifyServerCertificate=true&useSSL=true&requireSSL=false&serverTimezone=UTC";
            conn = DriverManager.getConnection(url, user, password);

        } catch (SQLException e) {
            System.out.println("error!!!!");
            System.out.println(e.getMessage());
            e.printStackTrace();
            return e.getMessage();
        }
        return conn.getCatalog();
    }

Mi archivo web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
        arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar &quot;%HOME%\site\wwwroot\demo-0.0.1-SNAPSHOT.jar&quot;">
    </httpPlatform>
  </system.webServer>
</configuration>

Puede verificar los puntos a continuación si no puede conectarse a su base de datos:

1. No se olvide de configurar los parámetros SSL.

2. Establezca una IP address blanca de su aplicación web azul.

3. No te pierdas -Djava.net.preferIPv4Stack=true configuración en su web.config .

Puede encontrar más detalles en este hilo:JavaMail API to iMail -- java.net.SocketException:Permiso denegado:conectar

Espero que te ayude.