在SQL节点[192.168.99.88]上创建数据库且插入数据
mysql> create database world; Query OK, 1 row affected (0.09 sec) mysql> use world; Database changed mysql> CREATE TABLE `City` ( -> `ID` int(11) NOT NULL auto_increment, -> `Name` char(35) NOT NULL default '', -> `CountryCode` char(3) NOT NULL default '', -> `District` char(20) NOT NULL default '', -> `Population` int(11) NOT NULL default '0', -> PRIMARY KEY (`ID`) -> ) ENGINE=NDBCLUSTER DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.93 sec) mysql> INSERT INTO `City` VALUES (1,'Kabul','AFG','Kabol',1780000); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO `City` VALUES (2,'Qandahar','AFG','Qandahar',237500); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO `City` VALUES (3,'Herat','AFG','Herat',186800); Query OK, 1 row affected (0.00 sec) mysql> select * from City; +----+----------+-------------+----------+------------+ | ID | Name | CountryCode | District | Population | +----+----------+-------------+----------+------------+ | 3 | Herat | AFG | Herat | 186800 | | 1 | Kabul | AFG | Kabol | 1780000 | | 2 | Qandahar | AFG | Qandahar | 237500 | +----+----------+-------------+----------+------------+ 3 rows in set (0.00 sec)
在/usr/local/mysql/cluster-conf/config.ini添加
[mysqld] Id=5 Hostname=192.168.99.80 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
具体步骤如下:
[root@candyshop mysql]# vi /etc/my.cnf # Options for mysqld process: [mysqld] ndbcluster # run NDB storage engine ndb-connectstring=192.168.99.80 # location of management server # Options for ndbd process: [mysql_cluster] ndb-connectstring=192.168.99.80 # location of management server [root@candyshop mysql]# cd bin/ [root@candyshop bin]# cd .. [root@candyshop mysql]# ./bin/ndb_mgmd -f cluster-conf/config.ini [root@candyshop mysql]# ./bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: 192.168.99.80:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @192.168.99.89 (mysql-5.1.30 ndb-6.3.20, Nodegroup: 0, Master) id=3 @192.168.99.90 (mysql-5.1.30 ndb-6.3.20, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.99.80 (mysql-5.1.30 ndb-6.3.20) [mysqld(API)] 2 node(s) id=4 (not connected, accepting connect from 192.168.99.88) id=5 @192.168.99.80 (mysql-5.1.30 ndb-6.3.20)
启动节点:
[root@candyshop mysql]# ./bin/mysqld_safe & [1] 12009 [root@candyshop mysql]# 070917 19:40:47 mysqld_safe Logging to '/usr/local/mysql/data/candyshop.bee.com.err'. 070917 19:40:47 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data [root@candyshop mysql]# ./bin/mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.30-ndb-6.3.20-cluster-gpl MySQL Cluster Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | world | +--------------------+ 4 rows in set (0.00 sec) mysql> select * from world.City; +----+----------+-------------+----------+------------+ | ID | Name | CountryCode | District | Population | +----+----------+-------------+----------+------------+ | 1 | Kabul | AFG | Kabol | 1780000 | | 2 | Qandahar | AFG | Qandahar | 237500 | | 3 | Herat | AFG | Herat | 186800 | +----+----------+-------------+----------+------------+ 3 rows in set (0.07 sec)
发现之前在另外一个SQL节点[192.168.99.88]创建的数据库也出现在节点5[192.168.99.80]上面了。
这样整个安装和测试都完结了。