title: Spring Boot Data JPA Unable to Connect to VirtualBox Ubuntu MySQL Server
body: <p>I've posted a relatively similar question in the past <a href="https://stackoverflow.com/questions/61589940/spring-data-redis-unable-to-connect-to-virtualbox-ubuntu-redis-server">here</a>. I am attempting to configure my environment to work with VirtualBox so I can use Linux related tools to manage the servers. Currently, I am attempting to connect my Spring Boot web application to my Ubuntu MySQL server on my VirtualBox machine.</p>
  <h1>Problem</h1>
  <p>When attempting to connect to my MySQL server with my Spring Boot application, I received this error message:</p>
  <pre><code>2020-06-06 08:16:02.390  INFO 2936 --- [  restartedMain] c.c.mvcblog.SpringMvcBlogApplication     : Starting SpringMvcBlogApplication on DESKTOP-AS2P0GJ with PID 2936 (C:\Users\rocke\IdeaProjects\mvc-blog\target\classes started by rocke in C:\Users\rocke\IdeaProjects\mvc-blog)
  2020-06-06 08:16:02.396  INFO 2936 --- [  restartedMain] c.c.mvcblog.SpringMvcBlogApplication     : No active profile set, falling back to default profiles: default
  2020-06-06 08:16:02.480  INFO 2936 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
  2020-06-06 08:16:02.480  INFO 2936 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
  2020-06-06 08:16:04.076  INFO 2936 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFERRED mode.
  2020-06-06 08:16:04.215  INFO 2936 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 127ms. Found 2 JPA repository interfaces.
  2020-06-06 08:16:05.913  INFO 2936 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
  2020-06-06 08:16:05.940  INFO 2936 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2020-06-06 08:16:05.940  INFO 2936 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.35]
  2020-06-06 08:16:06.141  INFO 2936 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2020-06-06 08:16:06.141  INFO 2936 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3660 ms
  2020-06-06 08:16:06.474  INFO 2936 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
  2020-06-06 08:16:06.572  INFO 2936 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
  2020-06-06 08:16:06.672  WARN 2936 --- [  restartedMain] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
  2020-06-06 08:16:06.788  INFO 2936 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.15.Final
  2020-06-06 08:16:07.055  INFO 2936 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  2020-06-06 08:16:07.205  INFO 2936 --- [         task-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
  2020-06-06 08:16:10.357 ERROR 2936 --- [         task-1] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Exception during pool initialization.
  
  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.20.jar:8.0.20]
      at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-java-8.0.20.jar:8.0.20]
      at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.20.jar:8.0.20]
      at com.mysql.cj.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.20.jar:8.0.20]
      at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.20.jar:8.0.20]
      at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.20.jar:8.0.20]
      at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) ~[HikariCP-3.4.5.jar:na]
      at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:358) ~[HikariCP-3.4.5.jar:na]
      at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) ~[HikariCP-3.4.5.jar:na]
      at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:477) ~[HikariCP-3.4.5.jar:na]
      at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:560) ~[HikariCP-3.4.5.jar:na]
      at com.zaxxer.hikari.pool.HikariPool.&lt;init&gt;(HikariPool.java:115) ~[HikariCP-3.4.5.jar:na]
      at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-3.4.5.jar:na]
      at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.&lt;init&gt;(InFlightMetadataCollectorImpl.java:176) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:118) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1214) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1245) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
      at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
  Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
  </code></pre>
  <p>A handful of resources I found online related to this topic were dealing with invalid login attempts, invalid MySQL queries, or invalid dialects.</p>
  <h1>Debugging Information</h1>
  <p>I am able to ping the virtual machine when actively running. I ended up installing MySQL directly onto my local machine (Windows 10) and attempted to connect directly that way. After squashing a few bugs related to me using the wrong dialect, I was able to connect directly to my MySQL database on my local machine. However, switching back at that point to my Ubuntu hosted MySQL server still resulted in the same error message. I have also verified that the MySQL service is running. Lastly, I've also tried adding the 3306 port for MySQL.</p>
  <h1>Code</h1>
  <p>You can find my current repository <a href="https://github.com/CloakingOcean/mvc-blog" rel="nofollow noreferrer">here</a>. I'll show the most important pieces of my project here.</p>
  <p>application.properties</p>
  <pre><code>spring.datasource.driver-class-name = com.mysql.cj.jdbc.Driver
  spring.datasource.url=jdbc:mysql://192.168.0.101:3306/blog_db
  spring.datasource.username=root
  spring.datasource.password=mIThl
  
  # Configure Hibernate DDL mode: create / update
  spring.jpa.properties.hibernate.hbm2ddl.auto = create
  
  spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
  </code></pre>
  <p>Maven Pom Dependencies:</p>
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
      &lt;version&gt;2.3.0.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
      &lt;exclusions&gt;
          &lt;exclusion&gt;
              &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
              &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
          &lt;/exclusion&gt;
      &lt;/exclusions&gt;
  &lt;/dependency&gt;
  
  &lt;!-- https://mvnrepository.com/artifact/javax.validation/validation-api --&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;javax.validation&lt;/groupId&gt;
      &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
      &lt;version&gt;2.0.1.Final&lt;/version&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
      &lt;artifactId&gt;spring-data-jpa&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;mysql&lt;/groupId&gt;
      &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>Additionally, my Spring Boot Parent version is 2.3.0.RELEASE.</p>
  <p>I greatly appreciate any help given! I'm eager to improve my development process by incorporating VirtualBox VM's and am hoping to be able to find a resolution for this issue. Thank you!</p>