博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1.7. MySQL Custer
阅读量:6576 次
发布时间:2019-06-24

本文共 4557 字,大约阅读时间需要 15 分钟。

The cluster need a lot of server for experiments, if you haven't any server for one, I have a good idea that using Vmware for you.

at first, let's create lots of virtual machine(You MUST have a third server). and then follow me step by step learning how to set up a mysql cluster on your virtual machine.

mgm 		192.168.0.1		# Managementdata 		192.168.0.2		# Ndbd Nodedata 		192.168.0.3		# Ndbd Nodesql			192.168.0.4		# SQL Nodesql			192.168.0.5		# SQL Node

1.7.1. Management node (MGM node)

neo@mgm:~$ sudo vim /var/lib/mysql-cluster/config.ini[NDBD DEFAULT]NoOfReplicas=2DataMemory=80MIndexMemory=18M[MYSQLD DEFAULT][NDB_MGMD DEFAULT][TCP DEFAULT]portnumber=2202[NDB_MGMD]hostname=192.168.0.1datadir=/var/lib/mysql-cluster[NDBD]hostname=192.168.0.2datadir=/var/lib/mysql-cluster[NDBD]hostname=192.168.0.3datadir=/var/lib/mysql-cluster[MYSQLD]hostname=192.168.0.4[MYSQLD]hostname=192.168.0.5

1.7.2. Data node

my.cnf

neo@data:~$ sudo vim /etc/mysql/my.cnf[mysqld]ndbclusterndb-connectstring=192.168.0.1	# the IP of the MANAGMENT SERVER[mysql_cluster]ndb-connectstring=192.168.0.1	# the IP of the MANAGMENT SERVER

1.7.3. SQL node

my.cnf

neo@sql:~$ sudo vim /etc/mysql/my.cnf[mysqld]ndbclusterndb-connectstring=192.168.0.1	# the IP of the MANAGMENT SERVER[mysql_cluster]ndb-connectstring=192.168.0.1	# the IP of the MANAGMENT SERVER

1.7.4. Starting

  1. starting mgm

    neo@mgm:~$ sudo ndb_mgmd -f /var/lib/mysql-cluster/config.ini
  2. initial ndbd

    neo@data:~$ sudo ndbd --initial

    首次运行需要 --initial 参数,以后不需要。

1.7.5. Shutdown

MGM

$ sudo ndb_mgm -e shutdown

1.7.6. Testing

neo@mgm:~$ ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: localhost:1186Cluster Configuration---------------------[ndbd(NDB)]     2 node(s)id=2    @192.168.0.2  (Version: 5.0.51, Nodegroup: 0)id=3    @192.168.0.3  (Version: 5.0.51, Nodegroup: 0, Master)[ndb_mgmd(MGM)] 1 node(s)id=1    @192.168.0.1  (Version: 5.0.51)[mysqld(API)]   2 node(s)id=4    @192.168.0.4  (Version: 5.0.51)id=5    @192.168.0.5  (Version: 5.0.51)ndb_mgm>
[提示] 与没有使用簇的MySQL相比,在MySQL簇内操作数据的方式没有太大的区别。

执行这类操作时应记住三点

  1. 表必须用ENGINE=NDB或ENGINE=NDBCLUSTER选项创建,或用ALTER TABLE选项更改,以使用NDB Cluster存储引擎在 Cluster内复制它们。如果使用mysqldump的输出从已有数据库导入表,可在文本编辑器中打开SQL脚本,并将该选项添加到任何表创建语句,或用这类选项之一替换任何已有的ENGINE(或TYPE)选项。

  2. 另外还请记住,每个NDB表必须有一个主键。如果在创建表时用户未定义主键,NDB Cluster存储引擎将自动生成隐含的主键。(注释:该隐含 键也将占用空间,就像任何其他的表索引一样。由于没有足够的内存来容纳这些自动创建的键,出现问题并不罕见)。

  3. 当你在一个节点上运行create database mydb;你去其他sql node上执行show databases;将不能看到mydb,你需要创建它,然后use mydb; show tables;你将看到同步的表。

SQL Node 1

neo@sql:~$ mysql -uroot -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 7Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> create database cluster;Query OK, 1 row affected (0.00 sec)mysql> use clusterDatabase changedmysql> create table city( id mediumint unsigned not null auto_increment primary key, name varchar(20) not null default '' ) engine = ndbcluster default charset utf8;Query OK, 0 rows affected (1.07 sec)mysql> insert into city values(1, 'Shenzhen');Query OK, 1 row affected (0.12 sec)mysql> insert into city values(2, 'Guangdong');Query OK, 1 row affected (0.00 sec)

SQL Node 2

neo@sql:~$ mysql -uroot -pEnter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 7Server version: 5.0.51a-3ubuntu5.1 (Ubuntu)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || example            || mydb               || mysql              || neo                |+--------------------+6 rows in set (0.13 sec)mysql> create database cluster;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || cluster            || example            || mydb               || mysql              || neo                |+--------------------+6 rows in set (0.13 sec)mysql> use cluster;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> show tables;+-------------------+| Tables_in_cluster |+-------------------+| city              |+-------------------+1 row in set (0.01 sec)mysql> select * from city;+----+-----------+| id | name      |+----+-----------+|  1 | Shenzhen  ||  2 | Guangdong |+----+-----------+2 rows in set (0.03 sec)mysql>

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
android device action and adb command
查看>>
Makefile系列之五 :函数
查看>>
如何去掉私钥的密码
查看>>
jquery网页日历显示控件calendar3.1使用详解
查看>>
查看登陆系统用户的信息的三种方法详解
查看>>
apache调优隐藏版本信息及404重定向
查看>>
[Git] 关于refs/for/ 和refs/heads/
查看>>
LA 2572 Viva Confetti (Geometry.Circle)
查看>>
[NOI2015]程序自动分析
查看>>
innerHTML、innerText和outerHTML、outerText的区别
查看>>
__name__的意义与作用
查看>>
eclipse快捷键
查看>>
Java 异常
查看>>
Mysql 时间类型整理
查看>>
IOS调试—断点调试以及动态输出
查看>>
编译找错
查看>>
CSS边距---盒子模型
查看>>
Linux vi命令
查看>>
p1098 逆序对
查看>>
java防止浏览器直接打开下载的文件
查看>>