You must add the client option to the mysql-connector allowPublicKeyRetrieval=true this will allow the client to automatically request the public key from the server.
Also, note that AllowPublicKeyRetrieval=True could allow a malicious proxy to perform a Man-in-the-middle attack to get the plaintext password, so it is by default False and it must be explicitly enabled.
Check-out here.
You can also try adding useSSL=false when you are using it for testing/develop purposes.
Example:
jdbc:mysql://localhost:3306/db?allowPublicKeyRetrieval=true&useSSL=false
If you want to learn more about SQL, Check out this SQL Certification by Intellipaat.