MySQL資料庫管理(二)單機環境下MySQL Cluster的安裝

來源:互聯網
上載者:User

標籤:叢集   mysql cluster   

上文《MySQL資料庫管理(一)MySQL Cluster叢集簡介》對MySQL Cluster叢集做了簡要介紹,本文將教大家一步步搭建單機環境下的MySQL資料庫叢集。


一、單機環境搭建

    首先到MySQl官網上 下http://www.mysql.com/downloads/Cluster/下載所需的安裝包,然後將下載得到的ZIP包解壓到C:\ypl\mysql\mysqlc


    這個MySQL資料庫的叢集由一個MySQL服務引擎(mysqlds)、兩個資料節點(ndbd)和一個管理節點(ndb_mgmd)組成,所有的節點都運行在同一台機器上。依次建立以下檔案夾:
C:\ypl\mysql\my_Cluster
C:\ypl\mysql\my_Cluster\ndb_data
C:\ypl\mysql\my_Cluster\mysqld_data\ndbinfo
C:\ypl\mysql\my_Cluster\conf

之後,在C:\ypl\mysql\my_Cluster\conf檔案夾中建立下述兩個設定檔:
(1)my.cnf
    內容如下:
[mysqld]ndbClusterdatadir=C:\\ypl\\mysql\\my_Cluster\\mysqld_databasedir=C:\\ypl\\mysql\\mysqlcport=3306
(2)config.ini
    內容如下:
[ndb_mgmd]hostname=localhostdatadir=C:\ypl\mysql\my_Cluster\ndb_dataid=1[ndbd default]noofreplicas=2datadir=C:\ypl\mysql\my_Cluster\ndb_data[ndbd]hostname=localhostid=3[ndbd]hostname=localhostid=4[mysqld]hostname=localhost

mysqld進程需要一個名為mysql的系統資料庫,以儲存必要的系統資料和使用者資料。故需要進行以下操作:

  • 將C:\ypl\mysql\mysqlc\data\mysql整個檔案夾複製到C:\ypl\mysql\my_Cluster\ndb_data目錄下。
  • 將C:\ypl\mysql\mysqlc\data\ndbinfo整個檔案夾複製到C:\ypl\mysql\my_Cluster\ndb_data目錄下。

在上述工作完成後,即可啟動MySQL Cluster。


二、啟動節點:管理節點-->資料節點-->SQl節點

(1)啟動管理節點

進入命令列工具潔面後依次輸入命令:

cd  C:\ypl\mysql\my_Clusterstart /B C:\ypl\mysql\mysqlc\bin\ndb_mgmd -f conf\config.ini --initial --configdir=C:\ypl\mysql\my_Cluster\conf

結果如下:


(2)啟動資料節點

  • 啟動第一個資料節點,輸入命令:

start /B C:\ypl\mysql\mysqlc\bin\ndbd -c localhost:1186

  • 啟動第二個資料節點,輸入命令:

start /B C:\ypl\mysql\mysqlc\bin\ndbd -c localhost:1186


(3)啟動MySQl服務引擎

輸入命令:

start /B C:\ypl\mysql\mysqlc\bin\mysqld --defaults-file=conf\my.cnf

查看資料節點是否啟動完畢:

C:\ypl\mysql\mysqlc\bin\ndb_mgm  -e show

結果如下:

各個節點啟動成功後,可以在進程裡看到所有節點的進程。啟動工作管理員,將看到結果,

串連到MySQL伺服器,輸入命令:

C:\ypl\mysql\mysqlc\bin\mysql -u root -p123456


若串連成功,將出現如下介面:

三、測試

建立資料庫yplbeyond(注意使用ndb),在該資料庫內建立表users,並插入資料

drop database if exists yplbeyond;create database yplbeyond;use yplbeyond;create table users(id int(3) auto_increment not null primary key,uid char(50) not null,pwd char(50) not null,realname char(10) not null,phone char(10) not null,mail char(30) not null,date datetime null) engine=ndb;;insert into users values('','人 民 大 學','rucedu','lizi','00000000','[email protected]','');select * from users;



注意此時與在MySQL中建表不同,需要在表的末尾加上“engine=ndb;”,因為使用的是MySQL Cluster,標的儲存引擎是基於記憶體的NDB,而不是InnoDB。在檔案夾ypl內搜尋,可以查到C:\ypl\mysql\my_Cluster\ndb_data\ypl 目錄下有剛建立的表。同時應注意,當資料節點分布在不同機器上時,按InnoDB引擎儲存的資料在其它資料節點上查不到,可以做相應的實驗來驗證。

MySQL Cluster的服務必須手動停止,服務停止後,其它叢集節點可以使用管理節點(ndb_mgm)來停止。輸入命令:

C:\ypl\mysql\mysqlc\bin\ndb_mgm -e shutdownC:\ypl\mysql\mysqlc\bin\mysqladmin -u root -p123456 shutdown

結果如下:



MySQL資料庫管理(二)單機環境下MySQL Cluster的安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.