MySQL Cluster 搭建中對數(shù)據(jù)庫表的創(chuàng)建
MySQL Cluster 是MySQL數(shù)據(jù)庫主要適合于分布式計算環(huán)境的高實用、高冗余這兩種版本。MySQL Cluster 采用了NDB Cluster 存儲引擎,允許在一個 Cluster 中對MySQL服務(wù)器進行與運行。
在MyQL 5.0及以上的二進制版本中、以及與***的Linux版本兼容的RPM中提供了該存儲引擎。(注意,要想獲得MySQL Cluster 的功能,必須安裝 mysql-server 和 mysql-max RPM)。
目前能夠運行MySQL Cluster 的操作系統(tǒng)有Linux、Mac OS X和Solaris(一些用戶通報成功地在FreeBSD上運行了MySQL Cluster ,但MySQL AB公司尚未正式支持該特性)。
MySQL Cluster(MySQL 集群) 搭建中如何創(chuàng)建數(shù)據(jù)庫表
與沒有使用 Cluster的MySQL相比,在MySQL Cluster內(nèi)操作數(shù)據(jù)的方式?jīng)]有太大的區(qū)別。執(zhí)行這類操作時應(yīng)記住兩點:
表必須用ENGINE=NDB或ENGINE=NDBCLUSTER選項創(chuàng)建,或用ALTER TABLE選項更改,以使用NDB Cluster存儲引擎在 Cluster內(nèi)復(fù)制它們。如果使用mysqldump的輸出從已有數(shù)據(jù)庫導(dǎo)入表,可在文本編輯器中打開SQL腳本,并將該選項添加到任何表創(chuàng)建語句,或用這類選項之一替換任何已有的ENGINE(或TYPE)選項。
另外還請記住,每個NDB表必須有一個主鍵。如果在創(chuàng)建表時用戶未定義主鍵,NDB Cluster存儲引擎將自動生成隱含的主鍵。(注釋:該隱含 鍵也將占用空間,就像任何其他的表索引一樣。由于沒有足夠的內(nèi)存來容納這些自動創(chuàng)建的鍵,出現(xiàn)問題并不罕見)。
下面是一個例子:
在db2上,創(chuàng)建數(shù)據(jù)表,插入數(shù)據(jù):
- [db2~]root# mysql -uroot test
- [db2~]mysql> create table city(
- [db2~]mysql> id mediumint unsigned not null auto_increment primary key,
- [db2~]mysql> name varchar(20) not null default ''
- [db2~]mysql> ) engine = ndbcluster default charset utf8;
- [db2~]mysql> insert into city values(1, 'city1');
- [db2~]mysql> insert into city values(2, 'city2');
在db3上,查詢數(shù)據(jù):
- [db3~]root# mysql -uroot test
- [db2~]mysql> select * from city;
- +-----------+
- |id | name |
- +-----------+
- |1 | city1 |
- +-----------+
- |2 | city2 |
- +-----------+
安全關(guān)閉
要想關(guān)閉 Cluster,可在MGM節(jié)點所在的機器上,在Shell中簡單地輸入下述命令:
[db1~]root# /usr/local/mysql/ndb_mgm -e shutdown運行以下命令關(guān)閉SQL節(jié)點的mysqld服務(wù):
- [db2~]root# /usr/local/mysql/bin/mysqladmin -uroot shutdown
其他
關(guān)于MySQL Cluster更多詳細的資料以及備份等請參見MySQL手冊的“MySQL Cluster(MySQL 集群)”章節(jié)。