zoukankan      html  css  js  c++  java
  • 【spring boot】spring boot 2.0 项目中使用mysql驱动启动创建的mysql数据表,引擎是MyISAM,如何修改启动时创建数据表引擎为【spring boot 2.0】

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

    2018-05-14 14:16:37.283  INFO 7328 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
    Hibernate: drop table if exists hua_yang_area
    Hibernate: drop table if exists model_entity
    Hibernate: create table hua_yang_area (id bigint not null 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中一样

    server.port=9666
    
    
    #datasource
    spring.datasource.continue-on-error=false 
    spring.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=true
    spring.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

    重新启动:

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

    完整配置如下:

    server.port=9666
    
    
    #datasource
    spring.datasource.continue-on-error=false 
    spring.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=true
    spring.jpa.hibernate.ddl-auto=update
    spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
    View Code

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

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

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

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

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

    但是去查看源码,发现

    MySQL5InnoDBDialect

    已经被废弃了。

     最后找到 其实  MySQL57Dialect 和 MySQL55Dialect

    就可以创建InnoDB引擎。

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

  • 相关阅读:
    【其他】parallels Desktop解决无法压缩硬盘的问题
    【读书笔记】《互联网企业安全高级指南》1-5
    【漏洞复现】SMBLoris windows拒绝服务漏洞
    【编程开发】macOS下配置scapy环境
    C#异常处理经验(原则与方法)
    EntityFramework linq 多条件查询,不定条件查询
    C#制作、打包、签名、发布Activex全过程
    ZPL语言完成条形码的打印
    Linux环境下MySql安装和常见问题的解决
    lrzsz——一款好用的文件互传工具
  • 原文地址:https://www.cnblogs.com/sxdcgaq8080/p/9035890.html
Copyright © 2011-2022 走看看