Skip to content

Instantly share code, notes, and snippets.

@machuz
Last active June 12, 2017 15:42
Show Gist options
  • Save machuz/fe99f18709673af069bead057cd024fe to your computer and use it in GitHub Desktop.
Save machuz/fe99f18709673af069bead057cd024fe to your computer and use it in GitHub Desktop.
●OS
[ec2-user@ip-172-20-204-91 ~]$ uname -an
Linux ip-172-20-204-91 4.1.7-15.23.amzn1.x86_64 #1 SMP Mon Sep 14 23:20:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
●Embulk
Embulk v0.8.11
●MySQL
5.6.34
●cfg
```
in:
{% if env.EMBULK_ENV == 'production' %}{% include 'db/prod_slave' %}
{% elsif env.EMBULK_ENV == 'staging' %}{% include 'db/stg' %}
{% else %}{% include 'db/dev' %}
{% endif %}
{% include 'query/xxx' %}
column_options:
id: {type: string}
out:
{% if env.EMBULK_ENV == 'production' %}{% include 'db/prod_master' %}
{% elsif env.EMBULK_ENV == 'staging' %}{% include 'db/stg' %}
{% else %}{% include 'db/dev' %}
{% endif %}
// これ入れると化け回避→ options: {characterEncoding: "utf8"}
table: to_migration
mode: merge_direct
```
●移行元テーブル
```
> show create table from_migrate\G
*************************** 1. row ***************************
Table: from_migrate
Create Table: CREATE TABLE `from_migrate` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(127) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`created_at` timestamp(3) NOT NULL,
`updated_at` timestamp(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=369 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
```
●移行元DB
```
> show create database from_migrate_db;
+----------------+-------------------------------------------------------------------------+
| Database | Create Database |
+----------------+-------------------------------------------------------------------------+
| from_migrate_db | CREATE DATABASE `from_migrate_db` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------------+-------------------------------------------------------------------------+
```
●移行先テーブル
```
> show create table to_migrate\G
*************************** 1. row ***************************
Table: to_migrate
Create Table: CREATE TABLE `to_migrate` (
`id` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`name` varchar(127) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`created_at` timestamp(3) NOT NULL,
`updated_at` timestamp(3) NOT NULL,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
```
●移行先DB
> show create database to_migrate_db;
+--------------------+-----------------------------------------------------------------------------+
| Database | Create Database |
+--------------------+-----------------------------------------------------------------------------+
| to_migrate_db | CREATE DATABASE `to_migrate_db` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+--------------------+-----------------------------------------------------------------------------+
●文字コード周りの設定
> show variables like "chara%";
+--------------------------+-------------------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /rdsdbbin/mysql-5.6.34.R1/share/charsets/ |
+--------------------------+-------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment