Windows下搭建Mysql集群
Mysql集群的基本架构如下:
基本原理参考:【转】MySQL Cluster (集群)基本原理
这里采用最小配置,用两台机器来分别部署一个management 节点,2个data node, 2个sql node.
Management Node: 192.168.0.102
Data Node A: 192.168.0.102
Data Node B: 192.168.0.104
Sql Node A: 192.168.0.102
Sql Node B: 192.168.0.104
1. 首先从Mysql官方网站上下载最新的Mysql Cluster免安装包 (http://downloads.mysql.com/archives/cluster/)
注意我们下载的是ZIP Archive
2.将免安装包分别解压到两台机器的C:\Mysql文件夹下
3. 在Management Node的C:\Mysql\Bin下新建Config文件夹,用来存放cluster的配置文件。
3.1首先需要为management node创建一个默认配置文件my.ini ,内容如下:
[mysql_cluster]
# Options for management node process
config-file=C:/mysql/bin/config/config.ini3.2 创建整个cluster的配置文件config.ini
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas
DataDir=C:/mysql/bin/cluster-data # Directory for each data node's data files
# Forward slashes used in directory path,
# rather than backslashes. This is correct;
# see Important note in text
DataMemory=80M # Memory allocated to data storage
IndexMemory=18M # Memory allocated to index storage
# For DataMemory and IndexMemory, we have used the
# default values. Since the "world" database takes up
# only about 500KB, this should be more than enough for
# this example Cluster setup.[ndb_mgmd]
# Management process options:
HostName=192.168.0.102 # Hostname or IP address of management node
DataDir=C:/mysql/bin/cluster-logs # Directory for management node log files[ndbd]
# Options for data node "A":
# (one [ndbd] section per data node)
HostName=192.168.0.102 # Hostname or IP address[ndbd]
# Options for data node "B":HostName=192.168.0.104 # Hostname or IP address
[mysqld]
# SQL node A options:HostName=192.168.0.102 # Hostname or IP address
[mysqld]
# SQL node B options:HostName=192.168.0.104 # Hostname or IP address
4. 启动Management Node,命令如下:
c:\mysql\bin\ndb_mgmd.exe --configdir=c:\mysql\bin\config --config-file=c:\mysql\bin\config\config.ini --ndb-nodeid=1 --reload –initial
5.启动Data Node A,命令如下:
c:\mysql\bin\ndbd.exe --ndb-connectstring=192.168.0.102
6.启动Data Node B,命令如下:
c:\mysql\bin\ndbd.exe --ndb-connectstring=192.168.0.102
7.可以打开management client来查看cluster当前的状态
8.Data Node均启动后,接下来分别启动两个Sql Node,命令如下:
c:\mysql\bin\mysqld.exe --ndbcluster --ndb-connectstring=192.168.0.102 --console
9. 通过management client查看cluster的当前状态
10.至此,cluster已经成功启动。
11.在Sql Node A上创建数据库ClusterSample
注:默认root密码为空
12.在Sql Node A上创建数据表Person;
13. 通过Sql Node A插入数据;
14.在Sql Node B上去查询数据
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步