Spring boot 使用mysql实例详解

Spring boot 使用mysql实例详解

开发阶段用 H2即可,上线时,通过以下配置切换到mysql,spring boot将使用这个配置覆盖默认的H2。

1.建立数据库:

mysql -u root
CREATE DATABASE springbootdb

2.pom.xml:

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

3.application.properties:

spring.datasource.url= jdbc:mysql://localhost:3306/springbootdb
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create-drop//none, validate, update, create-drop

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!