mysql55dialect,【spring boot】spring boot 2.0 项目中使用mysql驱动启动创建的mysql数据表,引擎是MyISAM,如何修改启动时创建数据表引擎为【spri...

默认创建数据表使用的引擎是MyISAM

2018-05-14 14:16:37.283 INFO 7328 ---[ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect

Hibernate: drop tableifexists hua_yang_area

Hibernate: drop tableifexists model_entity

Hibernate: create table hua_yang_area (id bigint notnull auto_increment, create_date datetime not null, create_id varchar(255) not null, uid varchar(255) not null, update_date datetime, update_id varchar(255), area_name varchar(255) not null, area_person bigint not null, primary key (id)) engine=MyISAM

Hibernate: create table model_entity (key1 varchar(255) not null, key2 varchar(255) not null, key3 varchar(255) not null, password varchar(255), user_name varchar(255), primary key (key1, key2, key3)) engine=MyISAM

配置和之前spring boot中一样

cbdf1856ffba4c96cf8a0158d248426129f.jpg

ce857e33e078e26ced066c4fb8b56ab1cfb.jpg

server.port=9666#datasource

spring.datasource.continue-on-error=falsespring.datasource.url=jdbc:mysql://localhost:3306/swapping?useSSL=false&useUnicode=true&characterEncoding=UTF-8

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.database=mysql

spring.jpa.show-sql=truespring.jpa.hibernate.ddl-auto=update

spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5Dialect

View Code

但是如上所示,创建的mysql数据表 引擎为MyISAM

如果想创建时使用InnoDB引擎的话,需要在配置上加上【并且注意,要将方言删除】

添加这一句:

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

删除这一句:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

重新启动:

a4115e697ffe0bcbbe0d0d84f1a49a65.png

===========================================================

完整配置如下:

4d7200fff174e6b0882e3c40b43e2233969.jpg

dd3c7d4ed65c79d60e0b39ff993dd2b4405.jpg

server.port=9666#datasource

spring.datasource.continue-on-error=falsespring.datasource.url=jdbc:mysql://localhost:3306/swapping?useSSL=false&useUnicode=true&characterEncoding=UTF-8

spring.datasource.username=root

spring.datasource.password=root

spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.database=mysql

spring.jpa.show-sql=truespring.jpa.hibernate.ddl-auto=update

spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect

View Code

==========================================================

为什么使用InnoDB引擎,而不用MyISAM引擎?

因为前者支持事务,而后者不支持事务。

=========================最后,补充一点,这个和什么时候用有关系===================================

在上面配置中采用不同的方言,就能在创建数据表的时候使用不同的引擎去创建。

但是去查看源码,发现

MySQL5InnoDBDialect

已经被废弃了。

726254a6ab72ec26951d3d64bee61318.png

c2233ce1ac904a1cc489cdde5679d03d.png

最后找到 其实  MySQL57Dialect 和 MySQL55Dialect

就可以创建InnoDB引擎。

9e98acf5d81ab40c4f0c94b82b022027.png

所以就根据mysql的版本,采用合适的方言策略即可。例如,我是用的mysql5.5的所以就最后使用

0edbf7287baf69e0c807aa8269923916.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值