gpt4 book ai didi

mysql - Mysql:将字符集更改为UTF-8

转载 作者:行者123 更新时间:2023-12-02 19:18:09 25 4
gpt4 key购买 nike

我正在尝试使用docker-mysql设置Confluence。我已按照网上的所有说明进行操作,Confluence仍在给我Your database must be configured to either use utf8 or utf8mb4 as the default character set.
这是我的docker-compose:

version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- ./mycustom.cnf:/etc/mysql/conf.d/my.cnf
restart: always
command: --sql_mode=""
environment:
MYSQL_DATABASE: bachelorarbeit_database
# So you don't have to use root, but you can if you like
MYSQL_USER: horizon
# You can use whatever password you like
MYSQL_PASSWORD: 1P@ssw0rt123
# Password for root access
MYSQL_ROOT_PASSWORD: P@ssw0rt
MYSQL_ROOT_USER: root
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3310:3306'

这是与docker-compose位于同一目录中的 mycustom.cnf
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_bin
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=2GB
transaction-isolation=READ-COMMITTED
binlog_format=row

这是my.cnf文件
[mysqld]
character-set-server=utf8mb4
collation-server=utf8mb4_bin
default-storage-engine=INNODB
max_allowed_packet=256M
innodb_log_file_size=2GB
transaction-isolation=READ-COMMITTED
binlog_format=row

最佳答案

似乎默认情况下,使用docker-compose创建MySQL数据库时,默认情况下为latin1。

您可以通过在数据库服务中传递以下命令来覆盖它:

command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0

我不确定 --sql_mode=""在做什么,是否只是将参数传递给默认命令?如果是这样,您可能会将其添加到参数列表中。

重新启动容器后,可以登录mysql并运行以下SQL确认它现在是UTF-8:
mysql> SELECT @@character_set_database, @@collation_database;
+--------------------------+----------------------+
| @@character_set_database | @@collation_database |
+--------------------------+----------------------+
| utf8 | utf8_unicode_ci |
+--------------------------+----------------------+
1 row in set (0.00 sec)

关于mysql - Mysql:将字符集更改为UTF-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62019044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com