MySQL Database Management (2) Installation of MySQL Cluster in a single-host environment
AboveMySQL Database Management (1) MySQL Cluster IntroductionThis article briefly introduces the MySQL Cluster. We will teach you how to build a MySQL database Cluster in a single-host environment step by step.
I. Single-host environment construction
Download the required installation package from the MySQl official website, and decompress the downloaded ZIP package to C: \ ypl \ mysql \ mysqlc.
The MySQL database cluster consists of a MySQL service engine (mysqlds), two data nodes (ndbd), and a management node (ndb_mgmd). All nodes run on the same machine. Create the following folders in sequence:
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
Then, create the following two configuration files in the C: \ ypl \ mysql \ my_Cluster \ conf Folder:
(1) my. cnf
The content is as follows:
[mysqld]ndbClusterdatadir=C:\\ypl\\mysql\\my_Cluster\\mysqld_databasedir=C:\\ypl\\mysql\\mysqlcport=3306
(2) config. ini
The content is as follows:
[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
The mysqld process requires a system database named mysql to store necessary system data and user data. Therefore, you must perform the following operations:
Copy the entire C: \ ypl \ mysql \ mysqlc \ data \ mysql folder to the C: \ ypl \ mysql \ my_Cluster \ ndb_data directory. Copy the entire C: \ ypl \ mysql \ mysqlc \ data \ ndbinfo folder to the C: \ ypl \ mysql \ my_Cluster \ ndb_data directory.
After completing the preceding steps, you can start MySQL Cluster.
2. Start a node: Manage a node --> data node --> SQL Node
(1) Start the management Node
Enter the command line tool cleansing and then enter the command in sequence:
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
The result is as follows:
(2) Start a Data Node
Start the first data node and enter the following command:
start /B C:\ypl\mysql\mysqlc\bin\ndbd -c localhost:1186
Start the second data node and enter the following command:
start /B C:\ypl\mysql\mysqlc\bin\ndbd -c localhost:1186
(3) Start the MySQl service engine
Enter the following command:
start /B C:\ypl\mysql\mysqlc\bin\mysqld --defaults-file=conf\my.cnf
Check whether the data node has been started:
C:\ypl\mysql\mysqlc\bin\ndb_mgm -e show
The result is as follows:
After each node is started successfully, you can view the processes of all nodes in the process. Start the task manager and you will see the results,
Connect to the MySQL server and enter the following command:
C:\ypl\mysql\mysqlc\bin\mysql -u root -p123456
If the connection is successful, the following interface is displayed:
Iii. Test
Create a database yplbeyond (note that ndb is used), create a table users in the database, and insert data
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 ('', 'human University ', 'rucedu', 'lizi', '123', '11 @ 11 ', ''); select * from users;
Note::In this case, unlike creating a table in MySQL, you need to add "engine = ndb;" to the end of the table ;"Because MySQL Cluster is used, the underlying storage engine is memory-based NDB instead of InnoDB. Search in the ypl folder to find the created table in the C: \ ypl \ mysql \ my_Cluster \ ndb_data \ ypl directory. At the same time, it should be noted that when the data nodes are distributed on different machines, the data stored by the InnoDB engine cannot be found on other data nodes, and you can perform experiments to verify the data.
The MySQL Cluster service must be stopped manually. After the service is stopped, other Cluster nodes can use the management node (ndb_mgm) to stop the service. Enter the following command:
C:\ypl\mysql\mysqlc\bin\ndb_mgm -e shutdownC:\ypl\mysql\mysqlc\bin\mysqladmin -u root -p123456 shutdown
The result is as follows: