LoginSignup
0
0

More than 5 years have passed since last update.

docker上でMySQL Federated-Engineを試す

Last updated at Posted at 2017-04-10

コンテナの作成

docker run --name mysql56_1 -it mysql:5.6 /bin/bash
docker run --name mysql56_2 --link mysql56_1:m1 -it mysql:5.6 /bin/bash

mysql56_1,2の設定

mysql_install_db --datadir=/var/lib/mysql
cd /usr ; /usr/bin/mysqld_safe &
apt-get update
apt-get -y install vim
cat << EOS >> /etc/mysql/my.cnf
character-set-server=utf8

[mysql]
default-character-set=utf8
EOS
>ping m1

Federatedの設定

mysql56_1
CREATE TABLE `tb1` (
    `id` int NOT NULL,
    `name` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `tb1` ADD PRIMARY KEY (`id`);
ALTER TABLE `tb1` MODIFY `id` int NOT NULL AUTO_INCREMENT;
GRANT ALL ON mytest1.* TO fuser1@'%' IDENTIFIED BY 'password';
mysql56_2
mysql -u fuser1 -h m1 -p
mysql56_2
CREATE DATABASE mytest2;
use mytest2;

CREATE TABLE `tb1` (
    `id` int NOT NULL,
    `name` varchar(20) NOT NULL
) ENGINE=FEDERATED CONNECTION='mysql://fuser1:password@m1/mytest1/tb1';
mysql56_1
insert into tb1(name) value('abc');
mysql56_2
mysql> select * from tb1;
+----+------+
| id | name |
+----+------+
|  1 | abc  |
+----+------+
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0