search
HomeDatabaseMysql TutorialMysql cluster construction
Mysql cluster constructionMay 18, 2023 pm 06:01 PM

MySQL is a common relational database management system commonly used for data storage and management of web applications. As data volume and concurrent access continue to increase, the performance of a single MySQL instance may not meet the needs of the application. Therefore, MySQL Cluster has become a common solution. This article will introduce how to build a MySQL cluster.

Step one: Prepare the environment

Before starting to build the MySQL cluster, we need to prepare some environments and tools:

1. At least 3 servers, one of which As the management node, the remaining servers serve as MySQL nodes.

2. Ensure network communication between servers.

3. Install MySQL server and MySQL cluster software.

In this article, we will use Ubuntu 18.04 LTS operating system and MySQL Cluster version 7.6.21 for demonstration.

Step 2: Create a management node

The management node is used to manage the entire MySQL cluster, including creating and deleting MySQL nodes, routing query requests, etc. On this node, we need to install two software packages: MySQL Cluster Manager and MySQL Server.

1. Install MySQL Cluster Manager

MySQL Cluster Manager is a command line tool for automatically creating and configuring MySQL clusters. Install through the following command:

sudo apt-get update
sudo apt-get install mysql-cluster-manager

2. Install MySQL Server

on the management node , we need to install MySQL Server so that MySQL Cluster Manager can manage MySQL Cluster. Install through the following command:

sudo apt-get install mysql-server

3. Create MySQL Cluster configuration

On the management node, create the MySQL Cluster configuration file and specify Node address and port number. In this example, we assume that the management node's IP address is 192.168.1.100 and the port number is 1186.

Create a file named mycluster.ini and specify the node address and port number:

[NDB_MGMD DEFAULT]

Port the management server listens on

PortNumber=1186

[NDB_MGMD]

IP address of the management server node

HostName=192.168.1.100

[MYSQLD DEFAULT]
[NDBD DEFAULT]

[NDBD]

IP address of the first ndb node

HostName=192.168.1.101

[NDBD]

IP address of the second ndb node

HostName=192.168.1.102

4. Start the management node

Start the management node through the following command:

ndb_mgmd -f mycluster.ini --configdir=/var/lib/mysql-cluster

At this time, MySQL Cluster Manager will automatically create and configure the MySQL cluster. You can check the status of the MySQL cluster using the following command:

ndb_mgm
show

Step 3: Create a MySQL node

MySQL node is the one that actually stores and manages data server. In this example, we will create two MySQL nodes.

1. Install MySQL Cluster software

Before installing the MySQL Cluster software, make sure you have the necessary dependencies and libraries installed on your server. You can install it using the following command:

sudo apt-get install libaio1 libmecab2

Then download the MySQL Cluster binary package:

wget https://dev.mysql.com/get /Downloads/MySQL-Cluster-7.6/mysql-cluster_7.6.21-1ubuntu18.04_amd64.deb-bundle.tar

Unzip the downloaded package:

tar -xvf mysql-cluster_7.6.21- 1ubuntu18.04_amd64.deb-bundle.tar

Enter the decompressed directory:

cd mysql-cluster_7.6.21-1ubuntu18.04_amd64.deb-bundle

Execute the following command Install MySQL Cluster:

sudo dpkg -i mysql-common_7.6.21-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-cluster-client_7.6.21-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-cluster-server_7.6.21-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-cluster-client-core_7.6.21-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-cluster-server- core_7.6.21-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-cluster-community-client_7.6.21-1ubuntu18.04_amd64.deb
sudo dpkg -i mysql-cluster-community-server_7.6.21-1ubuntu18. 04_amd64.deb

2. Configure MySQL node

On the MySQL node, we need to modify the MySQL configuration file my.cnf and specify the management node and port number corresponding to the node.

Open the my.cnf file:

sudo nano /etc/mysql/my.cnf

At the end of the file, add the following configuration:

[mysqld ]
ndbcluster
ndb-connectstring=192.168.1.100

3. Start the MySQL node

Start the MySQL node through the following command:

sudo systemctl start mysql

4. Join the MySQL cluster

After the MySQL node is started, the MySQL Cluster Manager will automatically monitor and manage the MySQL node. You can check the status of your MySQL cluster using the following command:

ndb_mgm
show

At this point, you can create and manage databases on the MySQL node.

Step 4: Test MySQL Cluster

To ensure that MySQL Cluster is working properly, create a database on one of the MySQL nodes and extend its tables and data to other nodes. You can create a testdb database using the following command:

mysql -uroot -p
create database testdb;

Then, create a table for the database:

use testdb;
create table user(name VARCHAR(20), age INT);

Finally, insert some data on a node:

insert into user values('John', 18);

Then, use another MySQL node to check if the table exists:

use testdb;
select * from user;

If you can retrieve and read the data normally, then MySQL cluster has been successfully set up.

Summary

MySQL Cluster can greatly improve the performance and reliability of applications. Through the combination of management nodes and multiple MySQL nodes, automatic distribution and replication of data can be achieved, providing high availability and fault tolerance. In the above steps, we introduced how to build a MySQL cluster and conducted some tests and verifications. Depending on the specific application scenario, more configuration and optimization may be required. However, these steps can serve as a starting guide to help you get started learning and using MySQL Cluster.

The above is the detailed content of Mysql cluster construction. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

How do you handle large datasets in MySQL?How do you handle large datasets in MySQL?Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you drop a table in MySQL using the DROP TABLE statement?How do you drop a table in MySQL using the DROP TABLE statement?Mar 19, 2025 pm 03:52 PM

The article discusses dropping tables in MySQL using the DROP TABLE statement, emphasizing precautions and risks. It highlights that the action is irreversible without backups, detailing recovery methods and potential production environment hazards.

How do you represent relationships using foreign keys?How do you represent relationships using foreign keys?Mar 19, 2025 pm 03:48 PM

Article discusses using foreign keys to represent relationships in databases, focusing on best practices, data integrity, and common pitfalls to avoid.

How do you create indexes on JSON columns?How do you create indexes on JSON columns?Mar 21, 2025 pm 12:13 PM

The article discusses creating indexes on JSON columns in various databases like PostgreSQL, MySQL, and MongoDB to enhance query performance. It explains the syntax and benefits of indexing specific JSON paths, and lists supported database systems.

How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?How do I secure MySQL against common vulnerabilities (SQL injection, brute-force attacks)?Mar 18, 2025 pm 12:00 PM

Article discusses securing MySQL against SQL injection and brute-force attacks using prepared statements, input validation, and strong password policies.(159 characters)

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.