mysql用来开发中小型项目还是挺好用的,从节约成本的方面来考虑的确是个不错的选择,但是开发并发了比较大的项目显然还是有些吃力的,前几年解决这种问题通常是通过读写分离来优化数据库,因此出现了amoeba这个东西,现在这个东西已经被弃用了反倒是mysql-cluster-gpl用的比较多。但是有关mysql集群的配置还是比较繁琐,好多人弄不出来就放弃了,可怕的是网上很多资料都是转载别人的,都没有经过自己实际的验证,简直就是太坑爹了。这次我打算分享下有关mysql集群的知识。
1 开发准备
下载mysql-cluster-gpl-7.X版本的msi或者exe文件,双击后安装位置随意,安装好之后目录大致如下
2 创建于集群相关的文件目录
(1)在磁盘上建一个文件夹名称随意,在这个文件夹下面建mgm_data、ndb_data、mysqld_data,建好之后从mysql-cluster-gpl的安装目录下的bin目录下面复制ndb_mgm.exe和ndb_mgmd.exe到该目录下
(2)接着在ndb_data下面建ndb1和ndb2两个文件夹,并从mysql-cluster安装目录下的bin文件夹复制ndbd.exe到ndb1和ndb2文件夹下面
(3)然后在mysqld_data下面建mysqld1和mysqld2两个文件夹
(4)从mysql-cluster下面复制data、share目录,并从bin目录下复制mysqld.exe、mysqladmin.exe到mysqld1和mysqld2文件夹下面
(5)接下来创建两个my.ini文件内容如下
第一个:
[MYSQLD] ndbcluster datadir=D:/mydatabase/my_cluster/mysqld_data/mysqld1/data basedir=D:/MySQLCluster port=5000datadir配置的是数据库的数据目录,basedir配置的是mysql-cluster的安装目录
第二个:
[MYSQLD] ndbcluster datadir=D:/mydatabase/my_cluster/mysqld_data/mysqld2/data basedir=D:/MySQLCluster port=5001
第一个my.ini放在mysqld1文件夹下面,第二个则放在mysqld2文件夹下面
3 在基本目录下面创建一个名为config.ini的文件内容如下
[MYSQLD] Id=21 [MYSQLD] Id=22 [ndb_mgmd] hostname=localhost datadir=D:/mydatabase/my_cluster/mgm_data id=1 [NDBD DEFAULT] NoOfReplicas=2 DataMemory=80M IndexMemory=18M [ndbd] hostname=localhost id=11 [ndbd] hostname=localhost id=12datadir配置的是管理节点的目录,管理节点对数据节点和数据库服务节点进行统一管理
4 启动管理节点
命令为:ndb_mgmd.exe -f config.ini --initial
第一次启动的时候需要加--initial参数,但是后面启动的时候就不需要了
4 启动数据节点
分别进入每一个数据节点,也就是ndb1和ndb2目录下执行:ndbd -c localhost:1186
以同样的方式启动第二个数据节点
5 启动mysql服务节点
同样的进入mysql服务节点目录也就是mysqld1和mysqld2目录,执行:mysqld.exe --defaults-file=my.ini
还是以相同的方法启动第二个mysql服务节点
以防万一最好进入管理节点输入:ndb_mgm.exe之后在输入show回车,看看节点的状态是否正常
如图这种情况就说明节点都正常
6 接下来的工作就简单了,只需打开图形界面工具,连接5000和5001的数据库,接在在5000的这个mysql上随便建一个数据库并创建一张表,这里需要注意的是表的引擎应该使用ndb才可以。之后添加几条数据,我们可以看到在5001的mysql上也可以看到在5000上创建的数据库,且表的信息一致
为了能顺利执行各种命令,建议使用管理员身份执行命令,否则很有可能出现命令执行不成功的情况

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

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.