mysqldockerdocker-composemysql-cluster

MySQL Cluster - Create new table but not found in other mysql server


i Have create a mysql cluster with docker-compose.

version: '3.9'
services:
  management:
    image: mysql/mysql-cluster:8.0
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
    command: ndb_mgmd
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.1

  ndb1:
    image: mysql/mysql-cluster:8.0
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
    command: ndbd
    depends_on:
      - "management"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.21
  ndb2:
    image: mysql/mysql-cluster:8.0
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
    command: ndbd
    depends_on:
      - "management"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.22
  ndb3:
    image: mysql/mysql-cluster:8.0
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
    command: ndbd
    depends_on:
      - "management"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.23
  ndb4:
    image: mysql/mysql-cluster:8.0
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
    command: ndbd
    depends_on:
      - "management"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.24

  mysql1:
    image: mysql/mysql-cluster:8.0
    ports:
      - "2201:3306"
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
       - ./data/mysql1:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: bdteste
      MYSQL_USER: teste
      MYSQL_PASSWORD: teste
      MYSQL_ROOT_HOST: '%'
    command: mysqld
    depends_on:
      - "management"
      - "ndb1"
      - "ndb2"
      - "ndb3"
      - "ndb4"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.11

  mysql2:
    image: mysql/mysql-cluster:8.0
    ports:
      - "2202:3306"
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
       - ./data/mysql2:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: bdteste
      MYSQL_USER: teste
      MYSQL_PASSWORD: teste
      MYSQL_ROOT_HOST: '%'
    command: mysqld
    depends_on:
      - "management"
      - "ndb1"
      - "ndb2"
      - "ndb3"
      - "ndb4"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.12

  mysql3:
    image: mysql/mysql-cluster:8.0
    ports:
      - "2203:3306"
    volumes:
       - ./mysql.conf/my.cnf:/etc/my.cnf
       - ./mysql.conf/mysql-cluster.cnf:/etc/mysql-cluster.cnf
       - /etc/localtime:/etc/localtime:ro
       - ./data/mysql2:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: bdteste
      MYSQL_USER: teste
      MYSQL_PASSWORD: teste
      MYSQL_ROOT_HOST: '%'
    command: mysqld
    depends_on:
      - "management"
      - "ndb1"
      - "ndb2"
      - "ndb3"
      - "ndb4"
    networks:
      mysqlcluster:
        ipv4_address: 172.28.0.13

  adminer:
    image: adminer
    restart: always
    ports:
      - 8888:8080
    links:
      - mysql1:db
    networks:
      mysqlcluster:

networks:
 mysqlcluster:
  driver: bridge
  ipam:
   config:
    - subnet: 172.28.0.0/16
      gateway: 172.28.5.254

All running and work well :

bash-4.4# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 172.28.0.1:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 6 node(s)
id=21   @172.28.0.21  (mysql-8.0.30 ndb-8.0.30, Nodegroup: 0, *)
id=22   @172.28.0.22  (mysql-8.0.30 ndb-8.0.30, Nodegroup: 0)
id=23   @172.28.0.23  (mysql-8.0.30 ndb-8.0.30, Nodegroup: 1)
id=24   @172.28.0.24  (mysql-8.0.30 ndb-8.0.30, Nodegroup: 1)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @172.28.0.1  (mysql-8.0.30 ndb-8.0.30)

[mysqld(API)]   4 node(s)
id=11   @172.28.0.11  (mysql-8.0.30 ndb-8.0.30)
id=12   @172.28.0.12  (mysql-8.0.30 ndb-8.0.30)

From client i create new database and new table on 172.28.0.11 and i am insert new row, All work well. But if i am connect to 172.28.0.12 database exist but empty table, new table that i am create on 172.28.0.11 not detected on 172.28.0.12.

Any sugestions ? Thanks


Solution

  • Sorry, This my fault. Base on documentation

    https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-install-example-data.html

    We must create table with ENGINE=NDBCLUSTER

    After i recreate all table with ENGINE=NDBCLUSTER, every mysql server now sync the table. Thanks