[英]Unable to connect to mysql database running on a Virtualbox ubuntu VM with host-only network
我的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中僅主機適配器的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的連接工作正常。 但是,由於嘗試使用空用戶名登錄,因此身份驗證失敗,如異常所示:
java.sql.SQLException: Access denied for user ''@'192.168.56.15' (using password: NO)
您正在使用名為spring.datasource.data-username
和spring.datasource.data-password
屬性。 這些屬性對於Spring Boot來說是未知的。 正確的屬性是spring.datasource.username
和spring.datasource.password
:
spring.datasource.username=appuser
spring.datasource.password=******
常見屬性列表可在文檔中找到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.