我正在尝试使用 Java 连接器连接到(本地托管的)MySQL 服务器。我收到异常:
The server time zone value 'Mitteleurop�ische Sommerzeit' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
如您所见,时区值未正确传输,导致连接器无法理解时区。我已尝试将所有可能的设置设置为 UTF-8(JDBC URL 中的 useUnicode=true&characterEncoding=utf8
,character-set-server
也设置为 utf8
)。我在这里缺少什么?
最佳答案
据我所知,MySQL 服务器默认不使用 UTF-8。您必须在 my.cnf 中手动设置属性,如下所示:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
这些是 Linux 上配置文件的可能位置: /etc/my.cnf /etc/mysql/my.cnf /var/lib/mysql/my.cnf
关于java - 带有 JDBC 的 MySQL : Broken character encoding in Timezone string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40119215/