Skip to content

Instantly share code, notes, and snippets.

@siteslave
Created June 14, 2022 02:25
Show Gist options
  • Save siteslave/09ac21373df06065ea3df543aba11c3b to your computer and use it in GitHub Desktop.
Save siteslave/09ac21373df06065ea3df543aba11c3b to your computer and use it in GitHub Desktop.
MySQL Cluster with NDB
hostnamectl set-hostname mysql-xxxx

install mysql tools

wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb
sudo apt-get update
sudo apt-get install mysql-router
sudo apt-get install mysql-shell
sudo apt-get install mysql-community-server

Edit configure file.

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
sudo service mysql restart
create user 'root'@'%' identified by 'trantech@128';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
vi /etc/hosts
10.2.1.154  mysql-master1
10.2.1.144  mysql-master2
10.2.1.150  mysql-master3 
10.2.1.155  mysql-router

Login:

MySQL Console

mysqlsh
MySQL  JS > \connect --mysql root@localhost:3301

Add instance

dba.configureInstance("root@localhost:3303")

Create cluster

cluster = dba.createCluster("demo")
cluster.status()

Add instance to cluster

cluster.addInstance("root@localhost:3302")
cluster.addInstance("root@localhost:3303")
cluster.status()

Test

CREATE TABLE movies(title VARCHAR(50) NOT NULL,genre VARCHAR(30) NOT NULL,director VARCHAR(60) NOT NULL,release_year INT NOT NULL,PRIMARY KEY(title));

MySQL Router

Create bootstrap

mysqlrouter --bootstrap root@localhost:3301 --directory=demo_router

Running

mysqlrouter -c mysqlrouter.conf

Stop

\c root@localhost:3301
\sql stop group_replication;

Start

\c root@localhost:3301
\sql start group_replication;

MySQL Router

sudo mysqlrouter --bootstrap root@mysql-master1 --user=mysqlrouter

/etc/mysqlrouter/** rw, /var/lib/mysqlrouter/** rw,

MySQL Classic protocol

  • Read/Write Connections: localhost:6446
  • Read/Only Connections: localhost:6447

MySQL X protocol

  • Read/Write Connections: localhost:6448
  • Read/Only Connections: localhost:6449

Connect via mysqlsh

mysqlsh
\c root@localhost:6447
\sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment