Spring Boot 连接 MySQL8.0.16 报错。
Spring Boot 使用 Mybatis 连接 MySQL 的详细错误日志:
Caused by: com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error: GlobalConfigUtils setMetaData Fail ! Cause:java.sql.SQLException: The server time zone value ‘�й���ʱ��’ 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.
抛出异常是因为MySql服务器时区(继承自系统时区)的格式与mysql连接器所期望的格式不同。
1.降低mysql-connector-java
依赖版本
在我看来不建议,既然升级了数据库版本,数据库连接驱动自然要升级,更改好对应配置即可。
不过,降低版本的确可以解决这个问题,使用5.1.x
版本即可。
而6.0.x
及以上版本还会有Unable to load authentication plugin 'caching_sha2_password'
的问题,这里就细说,也不选择了。
示例:
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.48version>
dependency>
2.JDBC配置中增加mysql连接时区配置
在JDBC连接url后添加时区属性:serverTimezone=UTC
,其中UTC是统一标准世界时间。
但是,serverTimezone=UTC
这样设置的时区默认为0,而中国在东八区,通过这个配置写入到数据库的日期数据查看慢8到14个小时,会显得很诡异。
尽管在Java代码中可以指定时区去获取正确的时间,但平常在查看数据库的时候会误导信息查询。
所以,需要指定为中国时区的话,可以将配置修改为serverTimezone=GMT%2B8
。
具体配置如下:
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
关于时区:
UTC与GMT基本上等同,误差不超过0.9秒。
关于MySQL支持的时区:
通过mysql-connector-java
源码中com.mysql.cj.util.TimeUtil
类的TIME_ZONE_MAPPINGS_RESOURCE
属性,可以看到serverTimezone支持的相关设置在/com/mysql/cj/util/TimeZoneMapping.properties
文件中。
找到/com/mysql/cj/util/TimeZoneMapping.properties
文件,其中支持的时区内容如下:
#Windows Zones
#Mon Apr 24 23:22:45 WEST 2017
AUS\ Central\ Daylight\ Time=Australia/Darwin
AUS\ Central\ Standard\ Time=Australia/Darwin
AUS\ Eastern\ Daylight\ Time=Australia/Sydney
AUS\ Eastern\ Standard\ Time=Australia/Sydney
Afghanistan\ Daylight\ Time=Asia/Kabul
Afghanistan\ Standard\ Time=Asia/Kabul
Alaskan\ Daylight\ Time=America/Anchorage
Alaskan\ Standard\ Time=America/Anchorage
Aleutian\ Daylight\ Time=America/Adak
Aleutian\ Standard\ Time=America/Adak
Altai\ Daylight\ Time=Asia/Barnaul
Altai\ Standard\ Time=Asia/Barnaul
Arab\ Daylight\ Time=Asia/Riyadh
Arab\ Standard\ Time=Asia/Riyadh
Arabian\ Daylight\ Time=Asia/Dubai
Arabian\ Standard\ Time=Asia/Dubai
Arabic\ Daylight\ Time=Asia/Baghdad
Arabic\ Standard\ Time=Asia/Baghdad
Argentina\ Daylight\ Time=America/Buenos_Aires
Argentina\ Standard\ Time=America/Buenos_Aires
Astrakhan\ Daylight\ Time=Europe/Astrakhan
Astrakhan\ Standard\ Time=Europe/Astrakhan
Atlantic\ Daylight\ Time=America/Halifax
Atlantic\ Standard\ Time=America/Halifax
Aus\ Central\ W.\ Daylight\ Time=Australia/Eucla
Aus\ Central\ W.\ Standard\ Time=Australia/Eucla
Azerbaijan\ Daylight\ Time=Asia/Baku
Azerbaijan\ Standard\ Time=Asia/Baku
Azores\ Daylight\ Time=Atlantic/Azores
Azores\ Standard\ Time=Atlantic/Azores
Bahia\ Daylight\ Time=America/Bahia
Bahia\ Standard\ Time=America/Bahia
Bangladesh\ Daylight\ Time=Asia/Dhaka
Bangladesh\ Standard\ Time=Asia/Dhaka
Belarus\ Daylight\ Time=Europe/Minsk
Belarus\ Standard\ Time=Europe/Minsk
Bougainville\ Daylight\ Time=Pacific/Bougainville
Bougainville\ Standard\ Time=Pacific/Bougainville
Canada\ Central\ Daylight\ Time=America/Regina
Canada\ Central\ Standard\ Time=America/Regina
Cape\ Verde\ Daylight\ Time=Atlantic/Cape_Verde
Cape\ Verde\ Standard\ Time=Atlantic/Cape_Verde
Caucasus\ Daylight\ Time=Asia/Yerevan
Caucasus\ Standard\ Time=Asia/Yerevan
Cen.\ Australia\ Daylight\ Time=Australia/Adelaide
Cen.\ Australia\ Standard\ Time=Australia/Adelaide
Central\ America\ Daylight\ Time=America/Guatemala
Central\ America\ Standard\ Time=America/Guatemala
Central\ Asia\ Daylight\ Time=Asia/Almaty
Central\ Asia\ Standard\ Time=Asia/Almaty
Central\ Brazilian\ Daylight\ Time=America/Cuiaba
Central\ Brazilian\ Standard\ Time=America/Cuiaba
Central\ Daylight\ Time=America/Chicago
Central\ Daylight\ Time\ (Mexico)=America/Mexico_City
Central\ Europe\ Daylight\ Time=Europe/Budapest
Central\ Europe\ Standard\ Time=Europe/Budapest
Central\ European\ Daylight\ Time=Europe/Warsaw
Central\ European\ Standard\ Time=Europe/Warsaw
Central\ Pacific\ Daylight\ Time=Pacific/Guadalcanal
Central\ Pacific\ Standard\ Time=Pacific/Guadalcanal
Central\ Standard\ Time=America/Chicago
Central\ Standard\ Time\ (Mexico)=America/Mexico_City
Chatham\ Islands\ Daylight\ Time=Pacific/Chatham
Chatham\ Islands\ Standard\ Time=Pacific/Chatham
China\ Daylight\ Time=Asia/Shanghai
China\ Standard\ Time=Asia/Shanghai
Cuba\ Daylight\ Time=America/Havana
Cuba\ Standard\ Time=America/Havana
Dateline\ Daylight\ Time=Etc/GMT+12
Dateline\ Standard\ Time=Etc/GMT+12
E.\ Africa\ Daylight\ Time=Africa/Nairobi
E.\ Africa\ Standard\ Time=Africa/Nairobi
E.\ Australia\ Daylight\ Time=Australia/Brisbane
E.\ Australia\ Standard\ Time=Australia/Brisbane
E.\ Europe\ Daylight\ Time=Europe/Chisinau
E.\ Europe\ Standard\ Time=Europe/Chisinau
E.\ South\ America\ Daylight\ Time=America/Sao_Paulo
E.\ South\ America\ Standard\ Time=America/Sao_Paulo
Easter\ Island\ Daylight\ Time=Pacific/Easter
Easter\ Island\ Standard\ Time=Pacific/Easter
Eastern\ Daylight\ Time=America/New_York
Eastern\ Daylight\ Time\ (Mexico)=America/Cancun
Eastern\ Standard\ Time=America/New_York
Eastern\ Standard\ Time\ (Mexico)=America/Cancun
Egypt\ Daylight\ Time=Africa/Cairo
Egypt\ Standard\ Time=Africa/Cairo
Ekaterinburg\ Daylight\ Time=Asia/Yekaterinburg
Ekaterinburg\ Standard\ Time=Asia/Yekaterinburg
FLE\ Daylight\ Time=Europe/Kiev
FLE\ Standard\ Time=Europe/Kiev
Fiji\ Daylight\ Time=Pacific/Fiji
Fiji\ Standard\ Time=Pacific/Fiji
GMT\ Daylight\ Time=Europe/London
GMT\ Standard\ Time=Europe/London
GTB\ Daylight\ Time=Europe/Bucharest
GTB\ Standard\ Time=Europe/Bucharest
Georgian\ Daylight\ Time=Asia/Tbilisi
Georgian\ Standard\ Time=Asia/Tbilisi
Greenland\ Daylight\ Time=America/Godthab
Greenland\ Standard\ Time=America/Godthab
Greenwich\ Daylight\ Time=Atlantic/Reykjavik
Greenwich\ Standard\ Time=Atlantic/Reykjavik
Haiti\ Daylight\ Time=America/Port-au-Prince
Haiti\ Standard\ Time=America/Port-au-Prince
Hawaiian\ Daylight\ Time=Pacific/Honolulu
Hawaiian\ Standard\ Time=Pacific/Honolulu
India\ Daylight\ Time=Asia/Calcutta
India\ Standard\ Time=Asia/Calcutta
Iran\ Daylight\ Time=Asia/Tehran
Iran\ Standard\ Time=Asia/Tehran
Israel\ Daylight\ Time=Asia/Jerusalem
Israel\ Standard\ Time=Asia/Jerusalem
Jordan\ Daylight\ Time=Asia/Amman
Jordan\ Standard\ Time=Asia/Amman
Kaliningrad\ Daylight\ Time=Europe/Kaliningrad
Kaliningrad\ Standard\ Time=Europe/Kaliningrad
Korea\ Daylight\ Time=Asia/Seoul
Korea\ Standard\ Time=Asia/Seoul
Libya\ Daylight\ Time=Africa/Tripoli
Libya\ Standard\ Time=Africa/Tripoli
Line\ Islands\ Daylight\ Time=Pacific/Kiritimati
Line\ Islands\ Standard\ Time=Pacific/Kiritimati
Lord\ Howe\ Daylight\ Time=Australia/Lord_Howe
Lord\ Howe\ Standard\ Time=Australia/Lord_Howe
Magadan\ Daylight\ Time=Asia/Magadan
Magadan\ Standard\ Time=Asia/Magadan
Marquesas\ Daylight\ Time=Pacific/Marquesas
Marquesas\ Standard\ Time=Pacific/Marquesas
Mauritius\ Daylight\ Time=Indian/Mauritius
Mauritius\ Standard\ Time=Indian/Mauritius
Middle\ East\ Daylight\ Time=Asia/Beirut
Middle\ East\ Standard\ Time=Asia/Beirut
Montevideo\ Daylight\ Time=America/Montevideo
Montevideo\ Standard\ Time=America/Montevideo
Morocco\ Daylight\ Time=Africa/Casablanca
Morocco\ Standard\ Time=Africa/Casablanca
Mountain\ Daylight\ Time=America/Denver
Mountain\ Daylight\ Time\ (Mexico)=America/Chihuahua
Mountain\ Standard\ Time=America/Denver
Mountain\ Standard\ Time\ (Mexico)=America/Chihuahua
Myanmar\ Daylight\ Time=Asia/Rangoon
Myanmar\ Standard\ Time=Asia/Rangoon
N.\ Central\ Asia\ Daylight\ Time=Asia/Novosibirsk
N.\ Central\ Asia\ Standard\ Time=Asia/Novosibirsk
Namibia\ Daylight\ Time=Africa/Windhoek
Namibia\ Standard\ Time=Africa/Windhoek
Nepal\ Daylight\ Time=Asia/Katmandu
Nepal\ Standard\ Time=Asia/Katmandu
New\ Zealand\ Daylight\ Time=Pacific/Auckland
New\ Zealand\ Standard\ Time=Pacific/Auckland
Newfoundland\ Daylight\ Time=America/St_Johns
Newfoundland\ Standard\ Time=America/St_Johns
Norfolk\ Daylight\ Time=Pacific/Norfolk
Norfolk\ Standard\ Time=Pacific/Norfolk
North\ Asia\ Daylight\ Time=Asia/Krasnoyarsk
North\ Asia\ East\ Daylight\ Time=Asia/Irkutsk
North\ Asia\ East\ Standard\ Time=Asia/Irkutsk
North\ Asia\ Standard\ Time=Asia/Krasnoyarsk
North\ Korea\ Daylight\ Time=Asia/Pyongyang
North\ Korea\ Standard\ Time=Asia/Pyongyang
Omsk\ Daylight\ Time=Asia/Omsk
Omsk\ Standard\ Time=Asia/Omsk
Pacific\ Daylight\ Time=America/Los_Angeles
Pacific\ Daylight\ Time\ (Mexico)=America/Tijuana
Pacific\ SA\ Daylight\ Time=America/Santiago
Pacific\ SA\ Standard\ Time=America/Santiago
Pacific\ Standard\ Time=America/Los_Angeles
Pacific\ Standard\ Time\ (Mexico)=America/Tijuana
Pakistan\ Daylight\ Time=Asia/Karachi
Pakistan\ Standard\ Time=Asia/Karachi
Paraguay\ Daylight\ Time=America/Asuncion
Paraguay\ Standard\ Time=America/Asuncion
Romance\ Daylight\ Time=Europe/Paris
Romance\ Standard\ Time=Europe/Paris
Russia\ Time\ Zone\ 10=Asia/Srednekolymsk
Russia\ Time\ Zone\ 11=Asia/Kamchatka
Russia\ Time\ Zone\ 3=Europe/Samara
Russian\ Daylight\ Time=Europe/Moscow
Russian\ Standard\ Time=Europe/Moscow
SA\ Eastern\ Daylight\ Time=America/Cayenne
SA\ Eastern\ Standard\ Time=America/Cayenne
SA\ Pacific\ Daylight\ Time=America/Bogota
SA\ Pacific\ Standard\ Time=America/Bogota
SA\ Western\ Daylight\ Time=America/La_Paz
SA\ Western\ Standard\ Time=America/La_Paz
SE\ Asia\ Daylight\ Time=Asia/Bangkok
SE\ Asia\ Standard\ Time=Asia/Bangkok
Saint\ Pierre\ Daylight\ Time=America/Miquelon
Saint\ Pierre\ Standard\ Time=America/Miquelon
Sakhalin\ Daylight\ Time=Asia/Sakhalin
Sakhalin\ Standard\ Time=Asia/Sakhalin
Samoa\ Daylight\ Time=Pacific/Apia
Samoa\ Standard\ Time=Pacific/Apia
Singapore\ Daylight\ Time=Asia/Singapore
Singapore\ Standard\ Time=Asia/Singapore
South\ Africa\ Daylight\ Time=Africa/Johannesburg
South\ Africa\ Standard\ Time=Africa/Johannesburg
Sri\ Lanka\ Daylight\ Time=Asia/Colombo
Sri\ Lanka\ Standard\ Time=Asia/Colombo
Syria\ Daylight\ Time=Asia/Damascus
Syria\ Standard\ Time=Asia/Damascus
Taipei\ Daylight\ Time=Asia/Taipei
Taipei\ Standard\ Time=Asia/Taipei
Tasmania\ Daylight\ Time=Australia/Hobart
Tasmania\ Standard\ Time=Australia/Hobart
Tocantins\ Daylight\ Time=America/Araguaina
Tocantins\ Standard\ Time=America/Araguaina
Tokyo\ Daylight\ Time=Asia/Tokyo
Tokyo\ Standard\ Time=Asia/Tokyo
Tomsk\ Daylight\ Time=Asia/Tomsk
Tomsk\ Standard\ Time=Asia/Tomsk
Tonga\ Daylight\ Time=Pacific/Tongatapu
Tonga\ Standard\ Time=Pacific/Tongatapu
Transbaikal\ Daylight\ Time=Asia/Chita
Transbaikal\ Standard\ Time=Asia/Chita
Turkey\ Daylight\ Time=Europe/Istanbul
Turkey\ Standard\ Time=Europe/Istanbul
Turks\ And\ Caicos\ Daylight\ Time=America/Grand_Turk
Turks\ And\ Caicos\ Standard\ Time=America/Grand_Turk
US\ Eastern\ Daylight\ Time=America/Indianapolis
US\ Eastern\ Standard\ Time=America/Indianapolis
US\ Mountain\ Daylight\ Time=America/Phoenix
US\ Mountain\ Standard\ Time=America/Phoenix
UTC=Etc/GMT
UTC+12=Etc/GMT-12
UTC-02=Etc/GMT+2
UTC-08=Etc/GMT+8
UTC-09=Etc/GMT+9
UTC-11=Etc/GMT+11
Ulaanbaatar\ Daylight\ Time=Asia/Ulaanbaatar
Ulaanbaatar\ Standard\ Time=Asia/Ulaanbaatar
Venezuela\ Daylight\ Time=America/Caracas
Venezuela\ Standard\ Time=America/Caracas
Vladivostok\ Daylight\ Time=Asia/Vladivostok
Vladivostok\ Standard\ Time=Asia/Vladivostok
W.\ Australia\ Daylight\ Time=Australia/Perth
W.\ Australia\ Standard\ Time=Australia/Perth
W.\ Central\ Africa\ Daylight\ Time=Africa/Lagos
W.\ Central\ Africa\ Standard\ Time=Africa/Lagos
W.\ Europe\ Daylight\ Time=Europe/Berlin
W.\ Europe\ Standard\ Time=Europe/Berlin
W.\ Mongolia\ Daylight\ Time=Asia/Hovd
W.\ Mongolia\ Standard\ Time=Asia/Hovd
West\ Asia\ Daylight\ Time=Asia/Tashkent
West\ Asia\ Standard\ Time=Asia/Tashkent
West\ Bank\ Daylight\ Time=Asia/Hebron
West\ Bank\ Standard\ Time=Asia/Hebron
West\ Pacific\ Daylight\ Time=Pacific/Port_Moresby
West\ Pacific\ Standard\ Time=Pacific/Port_Moresby
Yakutsk\ Daylight\ Time=Asia/Yakutsk
Yakutsk\ Standard\ Time=Asia/Yakutsk
#Linked Time Zones alias
#Mon Apr 24 23:22:45 WEST 2017
Africa/Addis_Ababa=Africa/Nairobi
Africa/Asmara=Africa/Nairobi
Africa/Asmera=Africa/Nairobi
Africa/Bamako=Africa/Abidjan
Africa/Bangui=Africa/Lagos
Africa/Banjul=Africa/Abidjan
Africa/Blantyre=Africa/Maputo
Africa/Brazzaville=Africa/Lagos
Africa/Bujumbura=Africa/Maputo
Africa/Conakry=Africa/Abidjan
Africa/Dakar=Africa/Abidjan
Africa/Dar_es_Salaam=Africa/Nairobi
Africa/Djibouti=Africa/Nairobi
Africa/Douala=Africa/Lagos
Africa/Freetown=Africa/Abidjan
Africa/Gaborone=Africa/Maputo
Africa/Harare=Africa/Maputo
Africa/Juba=Africa/Khartoum
Africa/Kampala=Africa/Nairobi
Africa/Kigali=Africa/Maputo
Africa/Kinshasa=Africa/Lagos
Africa/Libreville=Africa/Lagos
Africa/Lome=Africa/Abidjan
Africa/Luanda=Africa/Lagos
Africa/Lubumbashi=Africa/Maputo
Africa/Lusaka=Africa/Maputo
Africa/Malabo=Africa/Lagos
Africa/Maseru=Africa/Johannesburg
Africa/Mbabane=Africa/Johannesburg
Africa/Mogadishu=Africa/Nairobi
Africa/Niamey=Africa/Lagos
Africa/Nouakchott=Africa/Abidjan
Africa/Ouagadougou=Africa/Abidjan
Africa/Porto-Novo=Africa/Lagos
Africa/Sao_Tome=Africa/Abidjan
Africa/Timbuktu=Africa/Abidjan
America/Anguilla=America/Port_of_Spain
America/Antigua=America/Port_of_Spain
America/Argentina/ComodRivadavia=America/Argentina/Catamarca
America/Aruba=America/Curacao
America/Atka=America/Adak
America/Buenos_Aires=America/Argentina/Buenos_Aires
America/Catamarca=America/Argentina/Catamarca
America/Cayman=America/Panama
America/Coral_Harbour=America/Atikokan
America/Cordoba=America/Argentina/Cordoba
America/Dominica=America/Port_of_Spain
America/Ensenada=America/Tijuana
America/Fort_Wayne=America/Indiana/Indianapolis
America/Grenada=America/Port_of_Spain
America/Guadeloupe=America/Port_of_Spain
America/Indianapolis=America/Indiana/Indianapolis
America/Jujuy=America/Argentina/Jujuy
America/Knox_IN=America/Indiana/Knox
America/Kralendijk=America/Curacao
America/Louisville=America/Kentucky/Louisville
America/Lower_Princes=America/Curacao
America/Marigot=America/Port_of_Spain
America/Mendoza=America/Argentina/Mendoza
America/Montreal=America/Toronto
America/Montserrat=America/Port_of_Spain
America/Porto_Acre=America/Rio_Branco
America/Rosario=America/Argentina/Cordoba
America/Santa_Isabel=America/Tijuana
America/Shiprock=America/Denver
America/St_Barthelemy=America/Port_of_Spain
America/St_Kitts=America/Port_of_Spain
America/St_Lucia=America/Port_of_Spain
America/St_Thomas=America/Port_of_Spain
America/St_Vincent=America/Port_of_Spain
America/Tortola=America/Port_of_Spain
America/Virgin=America/Port_of_Spain
Antarctica/McMurdo=Pacific/Auckland
Antarctica/South_Pole=Pacific/Auckland
Arctic/Longyearbyen=Europe/Oslo
Asia/Aden=Asia/Riyadh
Asia/Ashkhabad=Asia/Ashgabat
Asia/Bahrain=Asia/Qatar
Asia/Calcutta=Asia/Kolkata
Asia/Chongqing=Asia/Shanghai
Asia/Chungking=Asia/Shanghai
Asia/Dacca=Asia/Dhaka
Asia/Harbin=Asia/Shanghai
Asia/Istanbul=Europe/Istanbul
Asia/Kashgar=Asia/Urumqi
Asia/Katmandu=Asia/Kathmandu
Asia/Kuwait=Asia/Riyadh
Asia/Macao=Asia/Macau
Asia/Muscat=Asia/Dubai
Asia/Phnom_Penh=Asia/Bangkok
Asia/Rangoon=Asia/Yangon
Asia/Saigon=Asia/Ho_Chi_Minh
Asia/Tel_Aviv=Asia/Jerusalem
Asia/Thimbu=Asia/Thimphu
Asia/Ujung_Pandang=Asia/Makassar
Asia/Ulan_Bator=Asia/Ulaanbaatar
Asia/Vientiane=Asia/Bangkok
Atlantic/Faeroe=Atlantic/Faroe
Atlantic/Jan_Mayen=Europe/Oslo
Atlantic/St_Helena=Africa/Abidjan
Australia/ACT=Australia/Sydney
Australia/Canberra=Australia/Sydney
Australia/LHI=Australia/Lord_Howe
Australia/NSW=Australia/Sydney
Australia/North=Australia/Darwin
Australia/Queensland=Australia/Brisbane
Australia/South=Australia/Adelaide
Australia/Tasmania=Australia/Hobart
Australia/Victoria=Australia/Melbourne
Australia/West=Australia/Perth
Australia/Yancowinna=Australia/Broken_Hill
Brazil/Acre=America/Rio_Branco
Brazil/DeNoronha=America/Noronha
Brazil/East=America/Sao_Paulo
Brazil/West=America/Manaus
Canada/Atlantic=America/Halifax
Canada/Central=America/Winnipeg
Canada/East-Saskatchewan=America/Regina
Canada/Eastern=America/Toronto
Canada/Mountain=America/Edmonton
Canada/Newfoundland=America/St_Johns
Canada/Pacific=America/Vancouver
Canada/Saskatchewan=America/Regina
Canada/Yukon=America/Whitehorse
Chile/Continental=America/Santiago
Chile/EasterIsland=Pacific/Easter
Cuba=America/Havana
Egypt=Africa/Cairo
Eire=Europe/Dublin
Europe/Belfast=Europe/London
Europe/Bratislava=Europe/Prague
Europe/Busingen=Europe/Zurich
Europe/Guernsey=Europe/London
Europe/Isle_of_Man=Europe/London
Europe/Jersey=Europe/London
Europe/Ljubljana=Europe/Belgrade
Europe/Mariehamn=Europe/Helsinki
Europe/Nicosia=Asia/Nicosia
Europe/Podgorica=Europe/Belgrade
Europe/San_Marino=Europe/Rome
Europe/Sarajevo=Europe/Belgrade
Europe/Skopje=Europe/Belgrade
Europe/Tiraspol=Europe/Chisinau
Europe/Vaduz=Europe/Zurich
Europe/Vatican=Europe/Rome
Europe/Zagreb=Europe/Belgrade
GB=Europe/London
GB-Eire=Europe/London
GMT+0=Etc/GMT
GMT-0=Etc/GMT
GMT0=Etc/GMT
Greenwich=Etc/GMT
Hongkong=Asia/Hong_Kong
Iceland=Atlantic/Reykjavik
Indian/Antananarivo=Africa/Nairobi
Indian/Comoro=Africa/Nairobi
Indian/Mayotte=Africa/Nairobi
Iran=Asia/Tehran
Israel=Asia/Jerusalem
Jamaica=America/Jamaica
Japan=Asia/Tokyo
Kwajalein=Pacific/Kwajalein
Libya=Africa/Tripoli
Mexico/BajaNorte=America/Tijuana
Mexico/BajaSur=America/Mazatlan
Mexico/General=America/Mexico_City
NZ=Pacific/Auckland
NZ-CHAT=Pacific/Chatham
Navajo=America/Denver
PRC=Asia/Shanghai
Pacific/Johnston=Pacific/Honolulu
Pacific/Midway=Pacific/Pago_Pago
Pacific/Ponape=Pacific/Pohnpei
Pacific/Saipan=Pacific/Guam
Pacific/Samoa=Pacific/Pago_Pago
Pacific/Truk=Pacific/Chuuk
Pacific/Yap=Pacific/Chuuk
Poland=Europe/Warsaw
Portugal=Europe/Lisbon
ROC=Asia/Taipei
ROK=Asia/Seoul
Singapore=Asia/Singapore
Turkey=Europe/Istanbul
UCT=Etc/UCT
US/Alaska=America/Anchorage
US/Aleutian=America/Adak
US/Arizona=America/Phoenix
US/Central=America/Chicago
US/East-Indiana=America/Indiana/Indianapolis
US/Eastern=America/New_York
US/Hawaii=Pacific/Honolulu
US/Indiana-Starke=America/Indiana/Knox
US/Michigan=America/Detroit
US/Mountain=America/Denver
US/Pacific=America/Los_Angeles
US/Pacific-New=America/Los_Angeles
US/Samoa=Pacific/Pago_Pago
Universal=Etc/UTC
W-SU=Europe/Moscow
Zulu=Etc/UTC
#Standard (IANA) abbreviations
#Mon Apr 24 23:22:45 WEST 2017
AWST=Australia/Perth
BST=Europe/London
CAT=Africa/Maputo
ChST=Pacific/Guam
HDT=America/Adak
HKT=Asia/Hong_Kong
IDT=Asia/Jerusalem
JST=Asia/Tokyo
NDT=America/St_Johns
NST=America/St_Johns
NZDT=Pacific/Auckland
NZST=Pacific/Auckland
PKT=Asia/Karachi
SAST=Africa/Johannesburg
SST=Pacific/Pago_Pago
WAST=Africa/Windhoek
WIT=Asia/Jayapura
WITA=Asia/Makassar
配置中的中国时区信息如下:
可以看到,如果我们要设置中国时区,除了serverTimezone=GMT%2B8
,还可以设置为serverTimezone=Asia/Shanghai
。
关于MySQL时区设置:
对于上面提到的数据库连接时区配置为serverTimezone=UTC
后,保存在数据库中的日期数据显示异常,还可以通过修改MySQl的时区来解决这个问题。
方式一:在mysql命令行修改时区(不需要重启mysql,但是重启mysql后失效)
> set global time_zone = '+8:00'; ##修改mysql全局时区为北京时间,即我们所在的东8区
> set time_zone = '+8:00'; ##修改当前会话时区
> flush privileges; #立即生效
方式二:修改MySQL配置文件(重启后仍有效)
Linux下:
# vim /etc/my.cnf ##在[mysqld]区域中加上
default-time_zone = '+8:00'
# /etc/init.d/mysqld restart ##重启mysql使新时区生效
Window下:
# 打开 mysql-8.0.16-winx64\bin\my.ini 文件
# 在 [mysqld] 区域中加上
default-time_zone = '+8:00'
# 重启mysql使新时区生效