英文:
Deploying app in aws throws error java.sql.SQLException: No database selected
问题
好的,以下是翻译好的部分:
开发者们,我正在处理这个Angular+MySQL+Spring-Boot应用程序,我现在正处于将我的数据库导出到AWS的阶段,但由于某种原因,在测试了与MySQL Workbench的数据库连接之后,当我在application.properties中设置参数时,会出现错误:
java.sql.SQLException: 未选择数据库
AWS抛出的终端节点和端口分别是:
终端节点:bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
端口:3306
因此,在我的app.properties中使用这些元素,我只初始化了:
spring.datasource.url=jdbc:mysql://bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com:3306/restaurant_booking_ok?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=ssssssssssss
spring.datasource.password=sssssssssssssss
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate.SQL=debug
我在这里暴露了Workbench数据库及其终端节点的图像。
但是,每当我尝试访问应用程序中的任何端点时,都会出现“未选择数据库”的500错误。您能帮助我看看我漏掉了哪个步骤吗?
我知道这是很多代码,但我也附上了我的pom文件,以防您发现有什么问题:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>cubancoder</groupId>
<artifactId>restaurant-booking</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>restaurant-booking</name>
<description>Demo project for Spring Boot made on maven front end angular</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail
dependencia para el envio de emails -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.4.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.stripe/stripe-java dependencia para el wireling de pagos y demas-->
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>19.45.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
提前感谢您的帮助。
英文:
Good day developers , im working in this Angular+MySQL+Spring-Boot app, and i'm in that phase of exporting my database to AWS, but for any reason after having tested the database connection to my mySQL Workbench , when i set the parameters in the application.properties the error
appears.
java.sql.SQLException: No database selected
The endpoint AWS throws as well as the port are :
endpoint: bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
port: 3306
thus using this elements on my app.properties i just initialize
spring.datasource.url=jdbc:mysql://bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
:3306/restaurant_booking_ok?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
spring.datasource.username=ssssssssssss
spring.datasource.password=sssssssssssssss
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
logging.level.org.hibernate.SQL=debug
I'm exposing here the workbench database and its endpoint
But any time i try to reach whichever the endpoints in my app the error 500 of no database selected shows up. Could you help me to see what step im ommiting
I know is a lot of code but also i attach my pom in case you detect something is wrong there
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>cubancoder</groupId>
<artifactId>restaurant-booking</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>restaurant-booking</name>
<description>Demo project for Spring Boot made on maven front end angular</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.modelmapper/modelmapper -->
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>2.3.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail
dependencia para el envio de emails -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.4.6</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.stripe/stripe-java dependencia para el wireling de pagos
y demas-->
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>19.45.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Thanks in advance for your help
答案1
得分: 5
错误 java.sql.SQLException: No database selected
似乎是指数据库名称。
数据库名称在属性 spring.datasource.url
中设置正确,然而对于亚马逊 RDS 来说,只需将该属性指向端点即可(无需包含数据库名称)。请尝试以下操作:
spring.datasource.url=jdbc:mysql://bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
:3306
编辑:
我成功地重现了这个错误。问题在于亚马逊 RDS 默认情况下创建的是新的数据库实例,而不是数据库。要创建数据库,有以下选项需要设置:
另外,错误不会在连接到数据库后立即出现,而是在第一次查询之后(例如创建新表)出现。
将“Initial database name”设置为 mydb
,并且数据库实例 ID 为 database-instance-1
,那么 URL 将会是:
spring.datasource.url=jdbc:mysql://database-instance-1.blablabla.rds.amazonaws.com:3306/mydb
我知道你的 spring.datasource.url
看起来是正确的,并且你可以在 Workbench 中看到你的数据库,但我建议你使用亚马逊 RDS 仪表盘创建一个新的数据库实例,并根据上述说明设置数据库名称。
这并不是最终的答案,但我希望这个尝试能帮助你找出问题的原因。
英文:
The error java.sql.SQLException: No database selected
seems to refer to the database name.
The database name is set correctly in the property spring.datasource.url
, however for Amazon RDS it's enough to point that property to the endpoint (without the database name). Try the following:
spring.datasource.url=jdbc:mysql://bookingrestaurantok.clnhc7kmwszz.us-west-2.rds.amazonaws.com
:3306
Edit:
I was able to reproduce the error. The issue is that Amazon RDS by default creates a new database instance but not a database. To create a database there is this option to set:
Also, the error does not appear after connecting to the database, but only after the first query (for example creating a new table).
Setting "Initial database name" to mydb
and having a database instance id database-instance-1
, then the URL would be:
spring.datasource.url=jdbc:mysql://database-instance-1.blablabla.rds.amazonaws.com:3306/mydb
I know that your spring.datasource.url
looks correct and you can see your database in Workbench but I suggest you create a new database instance using the Amazon RDS dashboard and setting the database name as explained above.
It's not a definitive answer but I hope this tentative will let you figure out the cause of the issue.
答案2
得分: -1
- 请检查部署应用程序的节点与包含数据库的实例之间的连接情况。
- 您是否为两个节点提供了足够的通信权限?
- 从应用程序机器到数据库机器进行ping测试。
- 在应用程序机器上安装mysql客户端,尝试连接到数据库。
- 数据库在该数据库服务器中可用吗?
英文:
- Please check the connectivity between the node in which application is deployed and the instance in which DB is there.
- Have you provided enough permissions for both nodes for communications ?.
- Do ping from application machine to db machine.
- Install mysql client in application machine and try to connect to the db.
- Is the database available in that database server ?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论