🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this post, I will provide a solution for frequently occurring exceptions while working with MySQL database - "Connection Java-MySql: Public Key Retrieval is not allowed".
Problem
I have encountered this issue and below issue description.
I was using a MySQL database with Java using the MySQL-connector 8.0.13 version. Everything seems to be correct but I have this exception:
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
Stack Trace:
Exception in thread "main" java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:108) at
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) at
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at
com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) at com.mysql.cj.jdbc.ConnectionImpl.
(ConnectionImpl.java:444) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
Solution 1
First, you need to check whether your MySQL server is up and running on your machine or not. Before starting your Java or Spring Boot application, make sure that the MySQL server is up and running on your machine.
Solution 2
If your MySQL server is running and still you are getting the same issue then try this solution.
Set AllowPublicKeyRetrieval=true to allow the client to automatically request the public key from the server.
allowPublicKeyRetrieval=true
You can also disable SSL and also suppress the SSL errors:
useSSL=false
Complete Code Snippet (Use this code)
private static String jdbcURL = "jdbc:mysql://localhost:3306/mysql_database?useSSL=false&allowPublicKeyRetrieval=true";
private static String jdbcUsername = "root";
private static String jdbcPassword = "root";
Reference
- https://stackoverflow.com/questions/50379839/connection-java-mysql-public-key-retrieval-is-not-allowed
- https://mysqlconnector.net/connection-options/
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
🆕 High-Demand
80–90% OFF
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
🆕 High-Demand
80–90% OFF
ChatGPT + Generative AI + Prompt Engineering for Beginners
🚀 Trending Now
80–90% OFF
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
🌟 Top Rated
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
🌟 Top Rated
80–90% OFF
Testing Spring Boot Application with JUnit and Mockito
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Master Spring Data JPA with Hibernate
🔥 Bestseller
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
🎓 Student Favorite
80–90% OFF
Available in Udemy for Business
Available in Udemy for Business
When I apply the above changes I get the below errors
ReplyDeletePublishing META-INF/context.xml configurations...
Could not load the context configuration for the web-student-tracker context due to a syntax error or other exception.
The reference to entity "allowPublicKeyRetrieval" must end with the ';' delimiter.
I am getting error "Access denied for user 'root'@'localhost' (using password: YES)"
ReplyDeleteCheck once your mysql password.
Delete