A few days ago, I found that the project that had been running could not be started locally:

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] the at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] at the mysql. Cj. JDBC. ConnectionImpl. CreateNewIO (ConnectionImpl. Java: 827) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] at the mysql. Cj. JDBC. ConnectionImpl. < init > (ConnectionImpl. Java: 447) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] at the mysql. Cj. JDBC. ConnectionImpl. GetInstance (ConnectionImpl. Java: 237) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] the at Com. Mysql. Cj. JDBC. NonRegisteringDriver. Connect (NonRegisteringDriver. Java: 199) ~ [mysql connector - Java - 8.0.17. Jar: 8.0.17] At com. Zaxxer. Hikari. Util. DriverDataSource. GetConnection (DriverDataSource. Java: 136) ~ [HikariCP - 3.2.0. Jar: na] the at Com. Zaxxer. Hikari. Pool. PoolBase. NewConnection (PoolBase. Java: 369) ~ [HikariCP - 3.2.0. Jar: na] the at Com. Zaxxer. Hikari. Pool. PoolBase. NewPoolEntry (PoolBase. Java: 198) ~ [HikariCP - 3.2.0. Jar: na] the at Com. Zaxxer. Hikari. Pool. HikariPool. CreatePoolEntry (HikariPool. Java: 467) [HikariCP - 3.2.0. Jar: na] the at Com. Zaxxer. Hikari. Pool. HikariPool. CheckFailFast (HikariPool. Java: 541) [HikariCP - 3.2.0. Jar: na] the at Com. Zaxxer. Hikari. Pool. HikariPool. < init > (HikariPool. Java: 115) [HikariCP - 3.2.0. Jar: na] the at Com. Zaxxer. Hikari. HikariDataSource. GetConnection (HikariDataSource. Java: 112) [HikariCP - 3.2.0. Jar: na] the at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86Invoke (< generated >) [HikariCP - 3.2.0. Jar: na]Copy the code

When I saw the Communications link failure, I initially thought it was due to timeout and network problems. However, after solving the network problems, I found that the same error was still reported, which was strange. Then I read the error log one by one and found:

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate) at Sun. Security. SSL. HandshakeContext. < init > (HandshakeContext. Java: 171) ~ [na: 1.8.0 comes with _292] the at Sun. Security. SSL. ClientHandshakeContext. < init > (ClientHandshakeContext. Java: 98) ~ [na: 1.8.0 comes with _292] the at Sun. Security. SSL. TransportContext. Kickstart (TransportContext. Java: 220) ~ [na: 1.8.0 comes with _292] the at Sun. Security. SSL. SSLSocketImpl. StartHandshake (SSLSocketImpl. Java: 428) ~ [na: 1.8.0 comes with _292] the at com.mysql.cj.protocol.ExportControlled.performTlsHandshake(ExportControlled.java:316) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] the at com.mysql.cj.protocol.StandardSocketFactory.performTlsHandshake(StandardSocketFactory.java:188) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] the at com.mysql.cj.protocol.a.NativeSocketConnection.performTlsHandshake(NativeSocketConnection.java:99) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17] the at com.mysql.cj.protocol.a.NativeProtocol.negotiateSSLConnection(NativeProtocol.java:331) ~ [mysql connector - Java - 8.0.17 jar: 8.0.17]... 68 common frames omittedCopy the code

See SSLHandshakeException? This error is quite unusual, and finally I found it on the Internet, and the problem was located:

1.8.0_281 was used before, but I did Homebrew a few days ago and found a new version of JDK 8, so I upgraded 1.8.0_292, and then found that the project could not start.

View/Library/Java/JavaVirtualMachines/adoptopenjdk – 8. The JDK/Contents/Home/jre/lib/security/Java security (Mac; Windows in the same way, in the jre/lib/security/Java security) found:

# Example:
# jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize < 2048JDK. TLS. DisabledAlgorithms = SSLv3, TLSv1 TLSv1.1, DES, RC4, MD5withRSA, \ DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \ include jdk.disabled.namedCurvesCopy the code
  • Method one:

    MySQL > delete from mysql.curl (); delete from mysql.curl ()

  • Method 2:

    Delete SSLv3, TLSv1, TLSv1.1 and save the java.security file. Restart the project to resolve the problem.

    # Example:
    # jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize < 2048
    jdk.tls.disabledAlgorithms=RC4, DES, MD5withRSA, \
        DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
        include jdk.disabled.namedCurves
    Copy the code
  • Method 3:

    Lowering the JDK from 1.8.0_292 to 1.8.0_281 or even 1.8.0_275 is fairly easy to do, but I don’t recommend it because Oracle supports JDK 8 until 2030:

Even if you have been using JDK 8 for a long time, JDK 8 itself will have minor iterations. For example, if you install JDK after 1.8.0_292 on a different computer next year, this problem will persist

  • Method 4:

    Method 1 resolves all problems caused by SSL call permissions, but breaks security. Method 2 resolves MySQL problems quickly. Method 3 is not recommended

    The basic idea is to be compatible with JDK 8 or even older versions of JDK, such as code level:

    private Socket overrideTlsProtocol(final Socket socket) {
        if(! (socketinstanceof SSLSocket)) {
            throw new RuntimeException("Error, an instance of SSLSocket is expected");
        }
        ((SSLSocket) socket).setEnabledProtocols(new String[]{"SSLv3"});
        return socket;
    }
    Copy the code

    Is amended as:

    private Socket overrideTlsProtocol(final Socket socket) {
        if(! (socketinstanceof SSLSocket)) {
            throw new RuntimeException("Error, an instance of SSLSocket is expected");
        }
        ((SSLSocket) socket).setEnabledProtocols(new String[]{"SSLv3"."TLSv1"."TLSv1.1"});
        return socket;
    }
    Copy the code

There are problems to face the problem, solve the problem, do not clap toss about, often tamper with these things, I believe you will benefit a lot, I hope to help you ~ 😄😄😄