windows 环境下搭建mysql cluster 集群详细步骤

1、环境准备

下载mysql集群版本,我这里下载的是mysql-cluster-8.0.39-winx64

https://dev.mysql.com/downloads/cluster/

2、创建配置文件

mysql集群版本下载以后解压后目录如下,创建配置文件 config.ini(集群配置文件,my.ini mysql配置文件)

192.168.0.84 配置文件

config.ini

(192.168.0.84 主服务器 下面是两台服务器 192.168.0.84 192.168.0.54)

复制代码
[ndb_mgmd]
NodeId=1
HostName=192.168.0.84
DataDir=F:/mysql-cluster-8.0.39-winx64/cluster-logs

[ndbd default]
NoOfReplicas=2
DataDir=F:/mysql-cluster-8.0.39-winx64/data
DataMemory=80M
IndexMemory=18M

[ndbd]
NodeId=2
HostName=192.168.0.84

[ndbd]
NodeId=3
HostName=192.168.0.54

[mysqld]
NodeId=4
HostName=192.168.0.84

[mysqld]
NodeId=5
HostName=192.168.0.54

my.ini(192.168.0.84 主服务器)

复制代码
[mysql]
default-character-set=utf8

[mysqld]
port=3307
default_authentication_plugin=mysql_native_password
basedir=F:/mysql-cluster-8.0.39-winx64/
datadir=F:/mysql-cluster-8.0.39-winx64/data/
character-set-server=utf8
default-storage-engine=ndbcluster
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'
innodb_buffer_pool_size=2G
innodb_lock_wait_timeout=30
innodb_log_buffer_size=8M
innodb_log_file_size=16M
join_buffer_size=200M
key_buffer_size=400M
log-error="F:/mysql-cluster-8.0.39-winx64/log-error.log"
log_error_verbosity=1
max_allowed_packet=50000M
max_connections=1000
max_heap_table_size=6400M
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=32M
read_buffer_size=4kb
read_rnd_buffer_size=4000M
server_id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=1800
interactive_timeout=86400
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
group_concat_max_len=1024000
ngram_token_size=2
innodb_ft_max_token_size=1
ft_min_word_len=1
[client]
port=3307
default-character-set=utf8

192.168.0.54配置文件

config.ini

复制代码
[ndbd]
NodeId=3
HostName=192.168.0.54
DataDir=F:/mysql-cluster-8.0.39-winx64/data

[ndbd default]
NoOfReplicas=2
DataDir=F:/mysql-cluster-8.0.39-winx64/data
DataMemory=80M
IndexMemory=18M

[ndb_mgmd]
# 仅在管理节点上配置
# NodeId=1
# HostName=192.168.0.84
# DataDir=F:/mysql-cluster-8.0.39-winx64/cluster-logs

[mysqld]
# 在数据节点上不需要此部分,SQL 节点需要配置

my.ini

复制代码
[mysql]
default-character-set=utf8

[mysqld]
port=3307
default_authentication_plugin=mysql_native_password
basedir=F:/mysql-cluster-8.0.39-winx64/
datadir=F:/mysql-cluster-8.0.39-winx64/data/
character-set-server=utf8
default-storage-engine=ndbcluster
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'
innodb_buffer_pool_size=16G
innodb_lock_wait_timeout=30
innodb_log_buffer_size=8M
innodb_log_file_size=16M
join_buffer_size=200M
key_buffer_size=400M
log-error="F:/mysql-cluster-8.0.39-winx64/data"
log_error_verbosity=1
max_allowed_packet=50000M
max_connections=1000
max_heap_table_size=6400M
myisam_max_sort_file_size=64G
myisam_sort_buffer_size=32M
read_buffer_size=4kb
read_rnd_buffer_size=4000M
server_id=1
skip-external-locking=on
sort_buffer_size=256kb
table_open_cache=256
thread_cache_size=16
tmp_table_size=64M
wait_timeout=1800
interactive_timeout=86400
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
group_concat_max_len=1024000
ngram_token_size=2
innodb_ft_max_token_size=1
ft_min_word_len=1
ndbcluster
ndb-connectstring=192.168.0.84
[client]
port=3307
default-character-set=utf8

3、初始化数据库(用管理员权限执行)

初始化192.168.0.84数据库

进入bin目录,执行 mysqld --initialize --console

初始化192.168.0.54数据库

进入bin目录,执行 mysqld --initialize --console

4、启动集群数据库

启动192.168.0.84数据库

(1)启动 ndb_mgmd 数据库管理节点

复制代码
ndb_mgmd.exe --config-file=F:\mysql-cluster-8.0.39-winx64\config.ini --configdir=F:\mysql-cluster-8.0.39-winx64

(2)启动数据节点 ndbd.exe

复制代码
ndbd.exe

(3) 启动数据库

复制代码
mysqld.exe --ndbcluster --ndb-connectstring=192.168.0.84 --console

启动192.168.0.54数据库

(1)启动数据节点 ndbd.exe 需要指定集群的主节点

复制代码
ndbd.exe --ndb-connectstring=192.168.0.84

(2)启动数据库

复制代码
mysqld.exe --ndbcluster --ndb-connectstring=192.168.0.84 --console

5、集群环境搭建完成

使用数据库连接工具,测试。

注意:创建表时必须指定 ENGINE=ndbcluster,才能确保表在 MySQL Cluster 环境中创建并利用集群的特性。这是因为 MySQL Cluster 是一个分布式数据库,使用了专门的存储引擎 NDB (Network Database),它与传统的 InnoDB 或 MyISAM 存储引擎不同。

6、为什么需要指定 ENGINE=ndbcluster

(1)数据分布 : NDB 存储引擎支持将数据分布到多个数据节点,这样可以提高数据的可靠性和性能。

(2)高可用性 : NDB 存储引擎能够自动处理数据副本和故障转移,从而提高系统的可用性。

(3)一致性 : 在 MySQL Cluster 中,NDB 引擎保证了数据在所有数据节点上的一致性。

相关推荐
程序新视界5 小时前
MySQL中什么是回表查询,如何避免和优化?
mysql
薛定谔的算法9 小时前
phoneGPT:构建专业领域的检索增强型智能问答系统
前端·数据库·后端
Databend11 小时前
Databend 亮相 RustChinaConf 2025,分享基于 Rust 构建商业化数仓平台的探索
数据库
得物技术12 小时前
破解gh-ost变更导致MySQL表膨胀之谜|得物技术
数据库·后端·mysql
Java水解12 小时前
【MySQL】从零开始学习MySQL:基础与安装指南
后端·mysql
Raymond运维16 小时前
MariaDB源码编译安装(二)
运维·数据库·mariadb
沢田纲吉16 小时前
🗄️ MySQL 表操作全面指南
数据库·后端·mysql
RestCloud1 天前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud1 天前
为什么说零代码 ETL 是未来趋势?
数据库·api
ClouGence1 天前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库