当前位置: 首页 > 知识库问答 >
问题:

无法将我的springboot API连接到MYSQL数据库

公孙河
2023-03-14

我设法将我的应用程序与HSQLDB连接起来,并使其运行良好。然而,我在将它连接到MySQL时遇到了一些麻烦。

下面是我的堆栈跟踪:

应用程序运行失败

null

我的pom.xml文件:

<?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.0.M3</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>14</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </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>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </pluginRepository>
</pluginRepositories>

null

这里是我的application.properties文件:

**spring.datasource.url** = jdbc:mysql://localhost:3306/springbootdb?useSSL=false
**spring.datasource.username** = thalysmg
**spring.datasource.password** =
## Hibernate Properties
**spring.jpa.properties.hibernate.dialect** = org.hibernate.dialect.MySQL5InnoDBDialect
**spring.jpa.hibernate.ddl-auto = update**

如果我没有错的话,我将MySQL用户配置为与我在ubuntu中的系统用户相同,这样我就可以用“mysql-u thalysmg”启动MySQL控制台,而不必键入我的密码。我已经试过使用“root”而不是“thalysmg”,并且试过使用和不使用我的密码。我到处寻找解决办法,但没有成功。希望任何人能帮助我!

共有1个答案

邹斌
2023-03-14

为什么在应用程序.属性中使用星型?删除它们

spring.datasource.url=jdbc:mysql://localhost:3306/springbootdb?useSSL=false
spring.datasource.username=thalysmg
spring.datasource.password=
## Hibernate Properties
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.hibernate.ddl-auto=update
 类似资料:
  • 我无法连接到MySQL数据库。它发生在更新MySQL和JDK之后。我添加了,但没有结果。这是我从eclipse中得到的一个例外: 不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45、5.6.26和5.7.6的要求,如果未设置explicit选项,默认情况下必须建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为“f

  • 问题内容: 所以我在用Java连接MySQL时遇到问题。这是我的代码: 我得到的错误是线程“ main”中的异常 http://postimg.org/image/593stjvjx/ 在mySQL工作台中,我的连接名是“ worlddb”,主机名是Liquidus(是本地主机) 套接字是MySQL 端口:3306 为什么是这样? 问题答案: 图片中的模式与连接的名称和Database,try w

  • 测试通过,即数据输入数据库,检查,一切正常。 但当我在调试模式下运行测试,在测试末尾放一个断点,尝试连接到数据库时,它是空的,连表都没有,更别提数据了。要连接,我使用dbever。在连接字符串中,我编写jdbc:h2:mem:mytestdb;db_close_on_exit=false(我尝试了jdbc:h2:tcp://localhost:9092/mem:mytestdb)。检查连接通过,写

  • 我现在面临这个问题已经有几天了。我正在尝试连接到计算机上的。但我没法把这事搞定。请参阅我运行的以下命令和错误消息。 警告:全局可写的配置文件“/etc/MySQL/my.cnf”被忽略错误2002(HY000):无法通过套接字“/var/run/mysqld/mysqld.sock”连接到本地MySQL服务器(111) 警告:全局可写的配置文件“/etc/MySQL/my.cnf”被忽略输入密码:

  • 我正在尝试从Spring Boot应用程序连接到mySQL数据库。然而,当我试图运行它时,它显示出错误。 我如何解决这个问题? 错误 从我的文件中添加代码片段 pom。xml 应用属性 堆栈跟踪 我还没有在sql中手动创建表,因为我认为spring.jpa.hibernate.ddl-Auto=date应该这样做

  • 我无法使用mysql节点包从node.js连接到我个人计算机上的本地mysql数据库。我的node.js程序与mysql数据库在同一台计算机上,因此不需要联网。我已经尝试了多个解决堆栈溢出的方法,但似乎都不起作用。 我的目录结构: connection.js的内容如下所示,错误出现在带有“connection.connect”的行上。我之所以知道这一点,是因为运行“function(err)”的回