简体   繁体   English

如何使用 CreateDatabaseIfNotExist 从 spring 开始使用 utf8mb4 字符集创建数据库?

[英]How can I create a database with utf8mb4 characterset from spring with CreateDatabaseIfNotExist?

In my Spring application.properties , I set the datasource to a MariaDB via JBDC.在我的 Spring application.properties ,我通过 JBDC 将数据源设置为 MariaDB。

spring.datasource.url=jdbc:mariadb://localhost:3306/dbname?createDatabaseIfNotExist=true

It successfully creates the MariaDB database.它成功地创建了 MariaDB 数据库。 However, the characterset and connectioncollation is set to latin1 .但是, characterset集和connectioncollation设置为latin1

Is there a way to create utf8mb4 databases with createDatabaseIfNotExist .有没有办法用createDatabaseIfNotExist创建utf8mb4数据库。 If not, is there a different method to create a database where I can specify utf8mb4 as the characterset and connectionsollation programmatically?如果没有,是否有不同的方法来创建一个数据库,我可以在其中以编程方式将utf8mb4指定为charactersetconnectionsollation picture of the databases数据库的图片

您可以使用以下字符串:

spring.datasource.url=jdbc:mariadb://localhost:3306/somedbname123?createDatabaseIfNotExist=true&useUnicode=true&character_set_server=utf8mb4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM