ラベル RDS の投稿を表示しています。 すべての投稿を表示
ラベル RDS の投稿を表示しています。 すべての投稿を表示

2011年5月26日木曜日

AWS RDS のタイムゾーンについて個人的まとめ

 RDSのタイムゾーンで色々試して、色々つまづいたのでまとめておく。

まず、2011/5/17現在、

RDSではtime_zoneの設定は出来ない。

USTの時刻がデフォルトとなっており、time_zoneは編集不可項目となっている。
参照:https://forums.aws.amazon.com/thread.jspa?threadID=38273 のNick@AWSさんの回答より。

代替案として次を試してみた。

  1. mysqlのコマンドから直接指定する。
  2. init_connectに、set time_zone = 'Asia/Tokyo'; を設定する。
ひとつずつ見ていくと、、、


  1. mysqlのコマンドから直接指定する。

まず、mysqlから GLOBAL time_zone を指定しようとすると、権限で怒られる。

mysql>  SET GLOBAL time_zone = '+9:00';
ERROR 1227 (42000): Access denied; you need the SUPER privilege for this operation

ただし、GLOBALじゃない、セッション毎の設定であればOK。

mysql> set time_zone = '+9:00';
Query OK, 0 rows affected (0.00 sec)

でも、これを毎回叩くのはどうだろう。プログラム側で対応しないといけないし、、、
う〜む。

こちらを参考にさせて頂きました。ありがとうございます。


ということで次。


     2. init_connectに、set time_zone = 'Asia/Tokyo'; を設定する。

これは、、、うまくいかなかった。
こちら↓を参照させて頂いてPHPスクリプトで、parameter group に設定しました。          

が、DBにつながらなくなってしまいました。。
厳密にはDBにはつながるのですが、SQLとか全て受け付けない、、、

mysql> show databases;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    19
Current database: *** NONE ***
ERROR 2013 (HY000): Lost connection to MySQL server during query

これでうまくいく環境もあるようですが、自分のところではダメでした。。
下記で同じ症状になっている方がいるようです。どうもリブートするとダメとか。

で、結論としては、タイムゾーンの設定はとりあえずプログラム側で、という切ない感じで。。

今後解決されることを切に願うばかりです、、、
誰かうまいやり方をされている方がいらっしゃいましたら、教えていただけると嬉しいですm(__)m

こちらに、プログラムでの対応案が書かれています。

AWS SDK for PHP の導入(simple版)

SDKの導入のメモ。
まぁ、Amazonのチュートリアル 通り。


◆SDKを下記サイトからダウンロード
   http://aws.amazon.com/sdkforphp

◆ダウンロードしたzipファイルを解凍
  > unzip sdk-latest.zip

◆回答したディレクトリ内のconfig-sample.inc.phpをコピー。
  > cp -p config-sample.inc.php config.inc.php

◆config.inc.php を下記のように修正。
値はAWSのアカウントページのセキュリティ証明書のページから取得する。
英語表記と日本語訳が微妙に異なってるので若干詰まった。

config.inc.php

/**
* Stores your AWS account information. Add your account information, and then rename this file
* to 'config.inc.php'.
*
* @version 2011.01.20
* @license See the included NOTICE.md file for more information.
* @copyright See the included NOTICE.md file for more information.
* @link http://aws.amazon.com/php/ PHP Developer Center
* @link http://aws.amazon.com/security-credentials AWS Security Credentials
*/
/**
* Amazon Web Services Key. Found in the AWS Security Credentials. You can also pass this value as the first
* parameter to a service constructor.
*/
define('AWS_KEY', '[アクセスキー ID]');
/**
* Amazon Web Services Secret Key. Found in the AWS Security Credentials. You can also pass this value as
* the second parameter to a service constructor.
*/
define('AWS_SECRET_KEY', '[シークレットアクセスキー]');
/**
* Amazon Account ID without dashes. Used for identification with Amazon EC2. Found in the AWS Security
* Credentials.
*/
define('AWS_ACCOUNT_ID', '[AWS アカウント ID]');
/**
* Your CanonicalUser ID. Used for setting access control settings in AmazonS3. Found in the AWS Security
* Credentials.
*/
define('AWS_CANONICAL_ID', '[標準ユーザーID]');
/**
* Your CanonicalUser DisplayName. Used for setting access control settings in AmazonS3. Found in the AWS
* Security Credentials (i.e. "Welcome, AWS_CANONICAL_NAME").
*/
define('AWS_CANONICAL_NAME', '[登録名]'); ※右上の、「ようこそ ~」の部分※以下は使ってないので未記入。
/**
* 12-digit serial number taken from the Gemalto device used for Multi-Factor Authentication. Ignore this
* if you're not using MFA.
*/
define('AWS_MFA_SERIAL', '');
/**
* Amazon CloudFront key-pair to use for signing private URLs. Found in the AWS Security Credentials. This
* can be set programmatically with .
*/
define('AWS_CLOUDFRONT_KEYPAIR_ID', '');
/**
* The contents of the *.pem private key that matches with the CloudFront key-pair ID. Found in the AWS
* Security Credentials. This can be set programmatically with .
*/
define('AWS_CLOUDFRONT_PRIVATE_KEY_PEM', '');
/**
* Set the value to true to enable autoloading for classes not prefixed with "Amazon" or "CF". If enabled,
* load `sdk.class.php` last to avoid clobbering any other autoloaders.
*/
define('AWS_ENABLE_EXTENSIONS', 'false');


これで準備オッケー。

おしまい。