mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| ndb_4_fs |
| ndbinfo |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.08 sec)
mysql> create database aa;
Query OK, 1 row affected (3.56 sec)
mysql> use aa
Database changed
mysql> CREATE TABLE ctest2 (i INT) ;
Query OK, 0 rows affected (24.71 sec)
mysql> INSERT INTO ctest2 () VALUES (1);
Query OK, 1 row affected (0.54 sec)
mysql> SELECT * FROM ctest2;
+------+
| i |
+------+
| 1 |
+------+
1 row in set (0.01 sec)
现在到另外一个数据节点db1查看下aa数据库是否同步过来了。
[root@db1 mysql-cluster]# mysql -u root
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| aa |
| mysql |
| ndb_3_fs |
| ndbinfo |
| performance_schema |
| test |
+--------------------+
7 rows in set (4.80 sec)
mysql> use aa
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from ctest2;
+------+
| i |
+------+
| 1 |
+------+
1 row in set (0.01 sec)
从上面可以看到数据已经同步了,mysql集群环境已经搭建完成。
九、破坏性测试
在上面可以看到172.16.1.74作为主的数据节点,现在把172.16.1.74这台机器关闭,有如下的结果:
[root@db1 mysql-cluster]# shutdown -h now
Broadcast message from root (pts/2) (Thu Oct 31 14:00:56 2013):
The system is going down for system halt NOW!
[root@db2 ~]# ndb_mgm -e show
Connected to Management Server at: 172.16.1.75:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 (not connected, accepting connect from 172.16.1.74)
id=3 @172.16.1.75 (mysql-5.5.31 ndb-7.2.13, Nodegroup: 0, Master)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @172.16.1.78 (mysql-5.5.31 ndb-7.2.13)
[mysqld(API)] 4 node(s)
id=4 (not connected, accepting connect from any host)
id=5 (not connected, accepting connect from any host)
id=6 @172.16.1.75 (mysql-5.5.31 ndb-7.2.13)
id=7 @172.16.1.75 (mysql-5.5.31 ndb-7.2.13)
id=8 (not connected, accepting connect from any host)
id=9 (not connected, accepting connect from any host)
从上面可以发现现在172.16.1.74这台机器的数据节点和sql节点已经连接不上了,172.16.1.75成为了主数据节点,现在在172.16.1.75数据节点上创建一个表,然后恢复172.16.1.74的数据节点,查看是否能够把数据同步过来了。
先在172.16.1.75数据节点做如下操作:
mysql> create table ctest3(id int(11)) ;
mysql> show tables;
mysql> create table ctest3(id int(11)) ;
Query OK, 0 rows affected (0.20 sec)
mysql> show tables;
+--------------+
| Tables_in_aa |
+--------------+
| ctest2 |
| ctest3 |
+--------------+
2 rows in set (0.00 sec)
mysql> insert into ctest3 values(1);
Query OK, 1 row affected (0.02 sec)