如果您的RDS MySQL实例的时区与您业务所在地域的时区不符,或者在夏令时和冬令时交替时需要校准实例的标准时间,可通过控制台或API接口修改实例的时区。本文介绍RDS MySQL实例时区的修改、验证方法和时区与UTC偏移量对照表。
在以下场景下,您需要修改RDS MySQL实例的时区: 系统中RDS MySQL实例的时区与您业务所在地域的时区不符,例如,2021年5月30日之前购买的RDS MySQL实例的默认时区为SYSTEM,需要修改为您业务所在地域的时区。 美国、加拿大、澳大利亚、欧洲等国家在夏令时和冬令时交替时,需要您手动调整所使用的标准时间。例如,英国在由冬令时转换为夏令时时,需要将冬令时时间(UTC)修改为夏令时时间( 时区参数修改后,需要重启实例才能生效。建议您在业务低峰期操作,并确保应用程序具有重连机制。 当MySQL的default_time_zone设为SYSTEM时可能存在以下风险: 主备时间不一致 高性能本地盘高可用实例可能因主备节点所在主机操作系统时区不同,造成MySQL主备时区不一致,极端场景下影响数据一致性。 实例性能下降 若业务中高频使用 JDBC与MySQL对于CST时区解析不一致 CST时区存在多义性:MySQL默认解析为 访问RDS实例列表,在上方选择地域,然后单击目标实例ID。 在左侧导航栏中,单击参数设置。 在可修改参数页签内找到 说明 单击提交参数,在弹出的对话框中,选择生效的时间段,完成后单击确定。 说明 参数的修改未提交时,如果想取消修改,请单击撤销。 请求示例 本示例调用ModifyParameter接口将时区参数default_time_zone修改为+9:00。 访问RDS实例列表,在上方选择地域,然后单击目标实例ID。 在左侧导航栏中,单击参数设置。 在参数修改历史页签内查看修改的时区参数值已生效。 参数 时区 标准时间偏移 备注 Afghanistan Standard Time (UTC+04:30) Kabul Alaskan Standard Time (UTC-09:00) Alaska Arabian Standard Time (UTC+04:00) Abu Dhabi, Muscat Atlantic Standard Time (UTC-04:00) Atlantic Time (Canada) AUS Central Standard Time (UTC+09:30) Darwin AUS Eastern Standard Time (UTC+10:00) Canberra, Melbourne, Sydney Belarus Standard Time (UTC+03:00) Minsk Canada Central Standard Time (UTC-06:00) Saskatchewan Cape Verde Standard Time (UTC-01:00) Cabo Verde Is. Cen. Australia Standard Time (UTC+09:30) Adelaide Central America Standard Time (UTC-06:00) Central America Central Asia Standard Time (UTC+06:00) Astana Central Brazilian Standard Time (UTC-04:00) Cuiaba Central Europe Standard Time (UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague Central European Standard Time (UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb Central Pacific Standard Time (UTC+11:00) Solomon Islands, New Caledonia Central Standard Time (UTC-06:00) Central Time (US and Canada) Central Standard Time (Mexico) (UTC-06:00) Guadalajara, Mexico City, Monterrey China Standard Time (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi E. Africa Standard Time (UTC+03:00) Nairobi E. Australia Standard Time (UTC+10:00) Brisbane E. Europe Standard Time (UTC+02:00) Chisinau E. South America Standard Time (UTC-03:00) Brasilia Eastern Standard Time (UTC-05:00) Eastern Time (US and Canada) Georgian Standard Time (UTC+04:00) Tbilisi GMT Standard Time (UTC) Dublin, Edinburgh, Lisbon, London Greenland Standard Time (UTC-03:00) Greenland Greenwich Standard Time (UTC) Monrovia, Reykjavik GTB Standard Time (UTC+02:00) Athens, Bucharest Hawaiian Standard Time (UTC-10:00) Hawaii India Standard Time (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi Jordan Standard Time (UTC+02:00) Amman Korea Standard Time (UTC+09:00) Seoul Middle East Standard Time (UTC+02:00) Beirut Mountain Standard Time (UTC-07:00) Mountain Time (US and Canada) Mountain Standard Time (Mexico) (UTC-07:00) Chihuahua, La Paz, Mazatlan US Mountain Standard Time (UTC-07:00) Arizona New Zealand Standard Time (UTC+12:00) Auckland, Wellington Newfoundland Standard Time (UTC-03:30) Newfoundland Pacific SA Standard Time (UTC-03:00) Santiago Pacific Standard Time (UTC-08:00) Pacific Time (US and Canada) Pacific Standard Time (Mexico) (UTC-08:00) Baja California Russia Standard Time (UTC+03:00) Moscow, St. Petersburg, Volgograd SA Pacific Standard Time (UTC-05:00) Bogota, Lima, Quito, Rio Branco SE Asia Standard Time (UTC+07:00) Bangkok, Hanoi, Jakarta China Standard Time (UTC+08:00) Kuala Lumpur, Singapore Tokyo Standard Time (UTC+09:00) Osaka, Sapporo, Tokyo US Eastern Standard Time (UTC-05:00) Indiana (East) UTC UTC Coordinated Universal Time UTC-02 (UTC-02:00) Coordinated Universal Time-02 UTC-08 (UTC-08:00) Coordinated Universal Time-08 UTC-09 (UTC-09:00) Coordinated Universal Time-09 UTC-11 (UTC-11:00) Coordinated Universal Time-11 UTC+12 (UTC+12:00) Coordinated Universal Time+12 W. Australia Standard Time (UTC+08:00) Perth W. Central Africa Standard Time (UTC+01:00) West Central Africa W. Europe Standard Time (UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna Kathmandu Time (UTC+5:45) Kathmandu Myanmar Time (UTC+6:30) Rangoon, Nay Pyi Taw Uzbekistan Time (UTC+5) Lahore, Karachi, Islamabad Samoa Western Standard Time (UTC+13) Nuku Alofa, Appiah UTC-12 (UTC-12) Coordinated Universal Time-12 购买实例时选择了UTC时区,但查询发现 在RDS MySQL中,创建实例时选择的UTC时区会直接映射为 更多详情,请参见MySQL官方社区教程(system_time_zone)。 通过API(ModifyParameter)修改应用场景
UTC+1) 。前提条件
注意事项
TIMESTAMP类型字段,可能因时区转换引发锁竞争问题,导致实例性能波动。详见如何处理由时区设置引发的 SQL 执行“卡顿”?。UTC+08:00中国标准时间,而部分JDBC版本(如8.0.22/23)会解析为UTC - 6美国中部时间。当主机操作系统时区为CST时,可能会导致JDBC向MySQL读取、写入的数据不符合预期。典型案例:The time zone CST has different meanings on MySQL Server and on conntector/j。在RDS控制台修改时区
default_time_zone参数,单击运行参数值,在弹出的对话框中修改时区的值。default_time_zone参数的取值含义,请参见时区与UTC偏移量对照表。调用API接口修改时区
...
// Parameter settings for API request
ModifyParameterRequest modifyParameterRequest = ModifyParameterRequest.builder()
.DBInstanceId("rm-bp1l94k5sw1zxxxxx")
.parameters("{"default_time_zone":"+9:00"}")
.forcerestart(true)
// Request-level configuration rewrite, can set Http request parameters, etc.
// .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
.build();
...JSON格式返回结果HTTP/1.1 200 OK
Content-Type:application/json
{
"RequestId": "6D698793-FC2B-5FC1-A6DF-33EDAD1AD6AB"
}验证时区修改结果
default_time_zone 的值已从 SYSTEM 变更为 +9:00。时区与UTC偏移量对照表
常见问题
system_time_zone显示为EDT?这是否会影响我的业务数据?default_time_zone参数的初始值。SQL查询的时间计算和存储行为由default_time_zone参数控制,因此在默认情况下,时间处理将按照UTC时区生效,详情请参见【产品/功能变更】新购RDS MySQL实例的默认时区由SYSTEM变更为UTC时区。system_time_zone仅表示MySQL启动时底层操作系统的时区,并不会直接影响SQL查询中的时间计算。但需注意,如果在实例创建后将default_time_zone修改为SYSTEM(不推荐,可能导致额外性能开销和相关风险),则SQL查询的时间计算会继承system_time_zone的时区设置,此时可能会对业务数据产生影响。您可以通过RDS控制台(修改时区)或API(ModifyParameter)修改default_time_zone取值。相关API
default_time_zone取值。