cool hit counter MySQL Cluster] - Configuring MySQL Cluster in Windows Environment_Intefrankly

MySQL Cluster] - Configuring MySQL Cluster in Windows Environment


Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/47441743

preamble


I recently used a MySQL cluster in a project, so I worked on it with my buddies for two days. I'll share the results with you below.

I have always felt that there is no better way to learn something new than to look at a picture as a way to understand it. So let's start with a diagram of the architecture of a mysql cluster (from Baidu's encyclopedia -MySQL Cluster):

The above diagram is divided into four layers: Applications, SQL, Storage, and Management. If your English wasn't taught by a gym teacher, then you must have guessed the responsibilities of each level: the

—– Applications are mainly applications that need to connect to a database. —– Each mysqld in SQL is a sql node, Applications need to connect to sql nodes to store data, you can think of it as a gate for applications to exchange data with the database cluster —– Storage has the meaning of 'repository', so the data is stored in the data nodes (ndbd), and the data is consistent in each data node, with a full set of up-to-date data —– Management is the management node, there is only one management node in a MySQL, which is used to manage other nodes

In summary, a MySQL cluster includes three types of nodes (excluding Applications): management nodes, data nodes, and sql nodes.


I. Download the clustered version of mysql

downloadingmysql-cluster-gpl-7.4.7-win32 perhapsmysql-cluster-gpl-7.4.7-winx64

downloadingaddress:http://yunpan.cn/cd892RtysQ3Vk (Extraction code: 45c8) MySQL official websitedownloadingaddress:http://dev.mysql.com/downloads/cluster/


II. Configuring MySQL Cluster

Three machines need to be used (consider a virtual machine if you don't have one), one configured with a management node: the other two with one data node and one SQL node each (or you can use five computers, one node per computer). Management node: 192.168.25.50 Data node A: 192.168.25.49 Data node B: 192.168.25.48 SQL Node A: 192.168.25.49 SQL Node B: 192.168.25.48

1、 start by placingdownloading The zip package is extracted to each computer'sC:/mysql directory:

2. Configuration management node

Create the cluster-logs and config folders in the C:MysqlBin directory on the computer that is configuring the management node (192.168.25.50). Cluster-logs is used to store log files, and two configuration files, my.ini and config.ini, are created in the config folder.

my.ini

[mysql_cluster] 
# Options for management node process 
config-file=C:/mysql/bin/config/config.ini

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.25.50              # 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":     
HostName=192.168.25.49              # Hostname or IP address

[ndbd] 
# Options for data node "B":
HostName=192.168.25.48              # Hostname or IP address

[mysqld] 
# SQL node A options:
HostName=192.168.25.49              # Hostname or IP address

[mysqld] 
# SQL node B options:
HostName=192.168.25.48              # Hostname or IP address

3. Configuring data nodes

Create the cluster-data folder in the C:MysqlBin directory on the computer where the data nodes are configured (192.168.25.48, 192.168.25.49) to store data in.

The SQL node does not need any configuration, and at this point, the entire MySQL cluster is built.

III. Starting a MySQL Cluster


When starting a MySQL cluster, there is a startup sequence: the management node is started first, then the data node, then the sql node.

1. Launch the management node.

Run the following command in cmd

c:mysqlin
db_mgmd.exe --configdir=c:mysqlinconfig --config-file=c:mysqlinconfigconfig.ini --ndb-nodeid=1 --reload –initial

2. Start each data node.

In cmd, run the following command.

c:mysqlin
dbd.exe --ndb-connectstring=192.168.25.50

3. Start each sql node.

In cmd, run the following command.

c:mysqlinmysqld.exe --ndbcluster --ndb-connectstring=192.168.25.50 --console

Now the entire MySQL cluster is up.

4. To view the status of each node.

Open ndb_mgm.exe on the computer where the management node is located (192.168.25.50), or run it directly in cmd

c:mysqlin
db_mgm

The connection status of each node can be viewed by executing the "show" command.

This indicates that each node is connected properly. Test data below.

IV. Testing MySQL Clusters


1. Create a database in sql node A and insert data.

Run C:mysqlinmysql.exe -u root -p command in cmd on sql node A's computer (192.168.25.49) to log in to mysql, the password defaults to empty when you need to enter it next (just enter).

Create database and insert data. -- Create a database named "MySQL_Cluster_Test".

 create database MySQL_Cluster_Test;

-- Create the table "T_User".

use MySQL_Cluster_Test;
create table T_User(Name varchar(32),Age int) engine=ndbcluster;

Note that the table build statement must be followed by engine=ndbcluster

-- Insert data.

insert into T_User values('DannyHoo',26);

--Search data.

select * from T_User;

2. The data can also be queried at sql node B.

Again run the command C:mysqlinmysql.exe -u root -p in cmd on sql node B's computer (192.168.25.48) to log in to mysql.

Execute show databases; command to view the new database created at sql node A. Execute use MySQL_Cluster_Test;     select * from T_User; The data inserted at sql node A can be queried.


At this point, the entire cluster is built and tested. If a data node goes down, it doesn't affect the whole cluster, and you don't have to worry if any data node dies or is even physically damaged, because each data node keeps a complete copy of the data (it automatically backs up the latest data to each data node for you when you manipulate it). You can test this by manually stopping one data node and sql node at this point and the other data node and sql node will still run normally. When you restart the stopped data nodes and sql nodes, you will find that you are connected to the cluster again and that the data is up to date for each data node.


Recommended>>
1、Artificial Intelligence Expert Zhang Jianwei Visits Henan Qidian
2、Issue 21 I uninstalled all my gossip news when I saw this app that allows me to buy celebrity time
3、SpringShedLock Guide
4、Introductory Basic Techniques to Break Windows 7 Boot Password in Seconds
5、Greater Bay Area 13th Blockchain Technology Application Salon

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号