AWS RDS

AWS上搭建数据库的时候,不是DB on EC2就是RDS,但是选择RDS时,Timezone怎么处理?

「面向全球提供的AWS来讲理所当然的是UTC」,而RDS也不是例外。把服务器迁移到AWS时,「数据库能不能使用中国时间」是常见的一个问题。 DB on EC2的话,配置一下系统的Timezone就可以,但是RDS是我们无法直接登录的因此需要使用MySQL的功能来实现。

介绍如何修改RDS MySQL的Timezone。

在RDS的Master用户不同于MySQL root用户,因此没有SUPER权限(管理者权限)。因此不能使用SET GLOBAL命令修改Timezone。在这里使用MySQL的init_connect参数里使用SET SESSION命令来修改Timezone。Init_conect参数实在Parameter Group里进行修改。

注意事项

  • rdsadmin用户貌似是AWS用来管理RDS实例的用户,无法判断影响范围因此不修改rdsadmin的Timezone。
  • 在init_connect参数里直接填写命令会无法正常运行,因此定义Stored Procedure,用CALL方式执行

操作流程如下

  1. 创建Stored Procedure
  2. 创建Parameter Group
  3. Parameter Grouup关联到RDS
  4. 重启RDS

1.创建Stored Procedure

以Master用户登录到RDS,shared Schema创建Stored Procedure(shared.store_time_zong)。

把时间配置为中国标准时间(Asia/Chongqing)。

 
1
2
3
4
5
6
7
8
9
10
11
mysql> CREATE DATABASE shared;
Query OK, 1 row affected (0.00 sec)
 
mysql> DELIMITER |
mysql> CREATE PROCEDURE shared.`store_time_zone`()
    -> IF (POSITION('aws_rds@' IN CURRENT_USER()) = 1) THEN
    -> SET SESSION time_zone = 'Asia/Chongqing';
    -> END IF |
Query OK, 0 rows affected (0.01 sec)
 
mysql> DELIMITER ;

确认Stored Procedure好不好用

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2015-04-09 05:10:41 |
+---------------------+
1 row in set (0.00 sec)
 
mysql> CALL shared.store_time_zone;
Query OK, 0 rows affected (0.07 sec)
 
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2015-04-09 13:10:52 |
+---------------------+
1 row in set (0.00 sec)

确认到时间变为中国标准时间(比UTC快8小时)。

2.创建Parameter Group

RDS上是以Parameter Group的形式来管理,MySQL的参数,在这里不修改默认的Parameter Group,创建一个Parameter Group。

  1. 点击:Parameter Groups
  2. 点击:Create Parameter Group

  1. Parameter Group Family:选择mysql5.6(因为我们的RDS MySQL版本是5.6.22)
  2. Group Name:timezone-Chongqing
  3. Description:init_connect call store_time_zone

  1. 选择:timezone-chongqing
  2. 点击:Edit Parameters

  1. init_connect:CALL shared.store_time_zone

  1. 点击:Save Changes

  1. 选择:RDS实例(awspack)
  2. 点击:Instance Actions
  3. 点击:Modify

  1. DB Parameter Group:timezone-chongqing
  2. 点击:Continue

  1. 确认:DB Parameter Group为timezone-chongqing
  2. 点击:Modify DB Instance

当用户连接到RDS时,通过init_connect调用Stored Procedure。

3. 重启RDS

重启RDS实例之前确认一下,Parameter Group的状态在applying

  1. 点击:RDS Dashboard的Instances
  2. 选择:RDS实例awspack
  3. 点击:Instance Actions
  4. 点击:Reboot

重启RDS实例之后确认,Parameter Group的状态为in-sync

以aws_rds用户登录到MySQL以后查看,时间为中国时间。

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$ mysql -h awspack.crhydmkxhg6d.ap-northeast-1.rds.amazonaws.com -uaws_rds -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.22-log MySQL Community Server (GPL)
 
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> show global variables like 'init_connect';
+---------------+-----------------------------+
| Variable_name | Value                       |
+---------------+-----------------------------+
| init_connect  | CALL shared.store_time_zone |
+---------------+-----------------------------+
1 row in set (0.00 sec)
 
mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2015-04-09 13:44:10 |
+---------------------+
1 row in set (0.00 sec)

更改 AWS RDS mysql时区 -摘自网络的更多相关文章

  1. AWS RDS mysql无法连接的问题

    rds创建后,无法连接mysql 检查安全组规则是否配置了 1. 2. 这样你的EC2就可以访问了.如果还不行,检查数据库是否和EC2在同一 VPC内. 官方文档:https://docs.amazo ...

  2. AWS EC2 MySQL迁移到RDS案例

    Amazon Relational Database Service (Amazon RDS) 是一种Web 服务,可让用户更轻松地在云中设置.操作和扩展关系数据库.它可以为行业标准关系数据库提供经济 ...

  3. 云厂商 RDS MySQL 怎么选

    1. 摘要 为了让大家更好的了解各云厂商在RDS MySQL数据库功能上的差异,也为给准备上云的同学做个参考,本文将对阿里云.腾讯云.华为云和AWS 的 RDS MySQL数据库进行对比说明. 从一个 ...

  4. Configure Amazon RDS mysql to store Chinese Characters

    Configure Amazon RDS mysql to store Chinese Characters https://dev.mysql.com/doc/refman/5.7/en/chars ...

  5. 关于阿里云 RDS mysql索引优化的一点经验

    2019年9月5日10:02:34 本地调试 git https://github.com/barryvdh/laravel-debugbar composer require barryvdh/la ...

  6. 实测:云RDS MySQL性能是自建的1.6倍

    1. 摘要 基于之前写的「云厂商 RDS MySQL 怎么选」的文章,为了进一步了解各云厂商在RDS MySQL数据库性能上的差异,本文将对自建MySQL.阿里云.腾讯云.华为云和AWS 的 RDS ...

  7. 万答17,AWS RDS怎么搭建本地同步库

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 背景说明 AWS RDS 权限受限,使用 mysqldump 的时候无法添加 - ...

  8. RDS MySQL 空间问题的原因和解决

    来源:https://help.aliyun.com/knowledge_detail/41739.html RDS MySQL 空间问题的原因和解决 更新时间:2016-07-22 17:20:14 ...

  9. 更改XAMPP中MySQL数据库的端口号

    更改XAMPP中MySQL数据库的端口号 如果电脑上已安装MySql数据库,还想用XAMPP中自带的数据库就需要更改XAMPP中数据库的端口号,避免和已安装的数据库冲突.本例以更改为3307端口号为例 ...

随机推荐

  1. iOS开发,更改状态栏(StatusBar)文字颜色为白色

    详细实现步骤 1.如图在Info.plist中进行设置,主要用于处理启动画面中状态栏(StatusBar)文字颜色. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...

  2. Maven 拾遗

    01. maven 概要 首先我把 maven 的概念快速的梳理一下,让我们快速地建立起一个比较精确的 maven 应用场景. maven 不是 ant,也不是 make,以前接触的构建工具,需要写一 ...

  3. OdiSendMail

    在Package中使用ODI自带的发送邮件OdiSendMail,生成的场景迁移到正式环境中,提示 javax.mail.AuthenticationFailedException: failed t ...

  4. MySQL参数化查询的IN 和 LIKE

    https://stackoverflow.com/questions/650455/c-sharp-parameterized-query-mysql-with-in-clausehttps://s ...

  5. Spring Cloud开发实践 - 03 - 接口实现和下游调用

    接口实现 Scot Commons Impl 接口实现模块 scot-commons-impl, 一方面实现了 scot-commons-api 的接口, 一方面将自己暴露为 REST 服务. 有4个 ...

  6. 转:Ogre源代码浅析——脚本及其解析(一)

    Ogre的许多外部资源数据都有着相应的脚本格式,现例举如下: Material(材质):Ogre使用的是“大材质”的概念.狭义的“材质”概念往往是与“贴图”等概念区分开的,比如在Lambert光照模型 ...

  7. windows上的Qt 5的依赖部署打包

    通常我们编译Qt程序的时候最终会生成exe或dll,这些可执行文件都会有Qt模块的依赖,如果项目一旦庞大,就不是很好看出缺了什么模块,导致安装包安装到其他绿色干净的windows机器上会提示缺少XXX ...

  8. 编译Boost库

    VS版本: 虽然网络上有,但是还是记录下,找到VS的command prompt,然后切换到boost的根目录: 1.运行 bootstrap.bat 它在当前目录下会生成b2.exe2. 2.运行b ...

  9. Anroid 4大组件之android.app.Service

    android.app.Service A Service is an application component representing either an application's desir ...

  10. Mysql模糊查询 select count(*) from sys_invitation where from_id like '%1006%';

    select count(*) from sys_invitation where from_id like '%1006%'; 查询结果 select * from sys_invitation w ...