java - Mysql 连接 Spring Boot 困难

标签 java mysql spring spring-boot

我是 Spring Boot 的新手,一直在尝试将它连接到我的 MySql 工作台。我用 web、jdbc、jpa 和 hibernate 开始了一个新的 Spring Boot 项目,但一直卡住了。

有很多关于这个主题的教程,但它们都以指出有必要进入 application.properties 文件并添加类似于以下的配置开始:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/mysqltutorial?useSSL=false
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

但是,我找到的所有教程都没有讨论如何查找 spring.datasource.url 甚至用户名或密码。

我如何找到更新这些应用程序属性以便我的 Mysql 工作台连接到我的 Spring Boot 应用程序?

最佳答案

在你的情况下, spring.datasource.url 等于 jdbc:mysql://localhost:3306/mysqltutorial?useSSL=false

分解:

jdbc:mysql://localhost:3306 是对在您机器上本地运行的 MySQL 的引用。默认情况下,MySQL 在端口 3306 上运行,但如果您愿意,可以更改它。此外,如果您想连接到在别处运行的数据库,可以从 localhost 更改地址。

mysqltutorial 是您在 MySQL 中创建的数据库的名称。

?useSSL=false 是连接数据库的附加属性。

接下来,
spring.datasource.usernamespring.datasource.password 是您在 MySQL 中用于数据库的密码和用户名。对于小型项目,您可以使用 root,但不建议将其用于更重要的项目,并且应创建具有不同权限的另一个用户。

关于java - Mysql 连接 Spring Boot 困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53643844/

相关文章:

java - 运行 Java 的 Azure 网站的 App_offline.htm 无法正常工作

java - Spring Boot 自定义 Bean 加载器

mysql - mysql中的随机字符串

java - 在测试上下文中禁用@Async 调用

spring - Grails Spring社交插件构建错误

java.sql.SQL语法错误异常 : ORA-01795: maximum number of expressions in a list is 1000

java - 在使用 PayPal 支付的 Gwt 项目中,我退出了页面,所以我失去了登录名

MySQL - 我的月份当前存储为 0-11

mysql - 如何创建一个表 'post',其中作者可以是各种类型

java - 加载资源 css 文件失败。自由标记