title: How to set up mySql JDBC connection with SSL
body: <pre><code>jdbc:mysql://localhost:3306/MyDb?verifyServerCertificate=true&amp;useSSL=true&amp;requireSSL=true
  </code></pre>
  
  <p>I downloaded the public certificate from the mySql server and put it into cacerts like this:</p>
  
  <pre><code>keytool.exe -import -alias mysql_dev \
      -keystore /c/dev/tools/Java/jre1.8.0_131/jre/lib/security/cacerts \
      -file rds-combined-ca-bundle.pem
  </code></pre>
  
  <p>I generated new keys using <code>keytool</code> like this:</p>
  
  <pre><code>keytool.exe -genkeypair -alias adam \
                 -keypass changeit \
                 -keysize 1024 \
                 -keystore /c/dev/.secure/haa2xt.jks \
                 -storepass changeit
  </code></pre>
  
  <p>So now I can see that Java is picking up both my key from the keystore and the server certificate from the truststore, but still I'm getting the <code>PKIX</code> error.</p>
  
  <blockquote>
    <p>PKIX path building failed:
    sun.security.provider.certpath.SunCertPathBuilderException: unable to
    find valid certification path to requested target</p>
  </blockquote>
  
  <p>I added this debug param to the command line and got some more info which all looks good, and I can see the mySql certificate in there.</p>
  
  <pre><code>-Djavax.net.debug=all
  </code></pre>
  
  <blockquote>
    <p>trustStore is: c:\dev\tools\java\jdk1.8.0_131\jre\lib\security\cacerts</p>
    
    <p>trustStore type is : jks</p>
  </blockquote>
  
  <p>[.....]</p>
  
  <blockquote>
    <p>keyStore is : C:/dev/.secure/haa2xt.jks</p>
    
    <p>keyStore type is : jks</p>
    
    <p>keyStore provider is :  </p>
    
    <p>init keystore </p>
    
    <p>init keymanager of type SunX509</p>
    
    <p>*** found key for : adam</p>
  </blockquote>
  
  <p>What have I done wrong?</p>