【问题标题】:Spring Boot connection to MySQL remote databaseSpring Boot 连接到 MySQL 远程数据库
【发布时间】:2018-11-23 01:53:24
【问题描述】:

我正在使用 Spring Boot 开发一个应用程序。我正在使用 phpMyAdmin(在我的大学是免费的)数据库进行持久化。我在远程服务器中有我的数据库。如何配置远程数据库连接的数据源?

请帮助我在属性文件和数据源 bean 配置中使用我的配置类中的注释进行配置。

例如:登录用户名:admin,密码:root

【问题讨论】:

  • 我需要使用数据库:“ii309808”
  • 很抱歉打破它,但 phpMyAdmin 只是一个与数据库交互的接口。您没有将 spring 应用程序连接到 phpMyAdmin。另外,请向我们展示您到目前为止所做的工作以及您为找出问题的解决方案所做的研究工作。
  • 远程 MySQL 服务器必须监听一个可公开访问的 IP 地址(通常 my.ini 已将 MySQL 配置为监听 127.0.0.1 - 这不会看到外部连接)。

标签: mysql spring spring-mvc spring-boot remote-server


【解决方案1】:

可能是这样的

在文件application.properties

spring.datasource.url=jdbc:mysql://lamp.ii.us.edu.pl:3306/ii309808
spring.datasource.username=admin
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

3306是MySQL数据库管理系统的默认端口号,如果无法通过端口3306连接,请咨询系统管理员)

参考:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-connect-to-production-database

【讨论】:

    猜你喜欢
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-14
    • 2020-05-05
    • 1970-01-01
    相关资源
    最近更新 更多