【问题标题】:Unable to connect to mysql database running on a Virtualbox ubuntu VM with host-only network无法连接到在仅主机网络的 Virtualbox ubuntu VM 上运行的 mysql 数据库
【发布时间】:2017-09-29 14:06:54
【问题描述】:

我在我的 Mac 上运行 VirtualBox,带有一个 IP 地址为 192.168.56.15 的仅限主机的网络适配器。我已将VM的IP地址设置为192.168.56.107

Host : MacOs High Sierra
Guest VM: Ubuntu

我已经在 VM 上安装并配置了一个 mysql 数据库,并且我已经将用户 appuser 设置为可以远程访问该数据库。

现在,在我的 Mac 上,当我尝试运行 springboot 应用程序时,我在 eclipse 中运行了一个 sprintboot 应用程序。我收到以下错误。

2017-09-29 14:43:02.545  INFO 3886 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-09-29 14:43:02.545  INFO 3886 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
Fri Sep 29 14:43:12 BST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2017-09-29 14:43:12.835 ERROR 3886 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

java.sql.SQLException: Access denied for user ''@'192.168.56.15' (using password: NO)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) ~[mysql-connector-java-5.1.44.jar:5.1.44]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973) ~[mysql-connector-java-5.1.44.jar:5.1.44]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909) ~[mysql-connector-java-5.1.44.jar:5.1.44]
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:873) ~[mysql-connector-java-5.1.44.jar:5.1.44]

为什么会出现这个错误?我已经指定了所有正确的值。这是我的 application.properties 文件。 注意错误中的IP是VirtualBox中host-only适配器的IP。

spring.datasource.url=jdbc:mysql://192.168.56.107:3306/appdatabase
spring.datasource.data-username=appuser
spring.datasource.data-password=******
spring.datasource.dbcp2.test-while-idle=true
spring.datasource.dbcp2.validation-query=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

如何解决此错误?

【问题讨论】:

    标签: mysql ubuntu spring-boot virtualbox


    【解决方案1】:

    您与 MySQL 的连接工作正常,因为您没有收到任何连接异常。但是,您的身份验证失败,因为您尝试使用空用户名登录,如异常所示:

    java.sql.SQLException: Access denied for user ''@'192.168.56.15' (using password: NO)
    

    您正在使用名为 spring.datasource.data-usernamespring.datasource.data-password 的属性。 Spring boot 不知道这些属性。正确的属性是spring.datasource.usernamespring.datasource.password

    spring.datasource.username=appuser
    spring.datasource.password=******
    

    常见属性列表可以在the documentation中找到。

    【讨论】:

    • 该死,我太傻了,我认为这与仅主机网络有关。我仍然想知道为什么它只使用主机的网络适配器 IP 地址。
    猜你喜欢
    • 2015-03-17
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多