文章目录
0x01、基本操作
ndb_mgm
show
:查询集群基本信息all report memoryusage
:查询集群资源用量
ndb_mgm工具
ndb_config
:/usr/local/mysql-cluster/bin/ndb_config -q 配置名称,查询mgm配置值,对应config.ini中的配合,未配置时显示系统默认。
0x02、常见问题
Code:1296
Error 904
Warning | 1296 | Got error 904 'Out of fragment records (increase MaxNoOfOrderedIndexes)' from NDB
/usr/local/mysql-cluster/bin/ndb_config -q MaxNoOfOrderedIndexes
查询一下当前值,默认为128
。
解决方法:修改或添加config.ini
中的MaxNoOfOrderedIndexes
属性的值。
Error 851
Warning | 1296 | Got error 738 'Record too big' from NDB
此错误为当前执行的SQL语句总的字段长度太长。 字段名称 类型(长度)
中的所有字段长度累加(不限于累加)长度超过8k。打个比方:vat_unit_addr varchar(500)
,这个字段(vat_unit_addr)长度为500。
解决方法:查看自己的SQL,总长度不得超过8k,根据业务需求,适当调整字段长度,或拆分表。
Error 851
Got error 851 'Fixed-size column offset exceeded max.Use VARCHAR or COLUMN_FORMAT DYNAMIC for memory-stored columns' from NDB
引用官方论坛上的解决办法:
In this case the VARCHAR(1000) columns will all take roughly 3000 bytes if utf8 (utf8mb3) is in use, or roughly 4000 bytes if utf8mb4 is in use.
Second, we have the limitations that all fixed fields on a row must start within the first 8188 bytes.
After the URL_B64S column the offset will be over beyond 8188 bytes, if utf8mb4 is in use offset may be too high already after HTML column.
简单讲,就是单个字段的长度太长,改小长度即可。
解决办法:将超过1000长度字段改小。
Error 707
Warning | 1296 | Got error 707 'No more table metadata records (increase MaxNoOfTables)' from NDB
此错误是默认ndb单库最多支持128张表,超过将无法创建更多表。
解决方法:添加或调整config.ini
中的MaxNoOfTables
属性。
Code:1297
Error 921
1297 - Got temporary error 921 'Out of transaction memory in local data manager, copy tuples (increase SharedGlobalMemory)' from NDBCLUSTER
此错误是由于SharedGlobalMemory
的值较小,根据需要增加即可。如果使用Navicat进行导入SQL数据,并且Set Autocommit =0
的时候,SQL文件过于大时,经常出现此错误。因此,根据SQL文件的大小以及批量commit数据的大小,设置相应的值。
0x03、磁盘表的创建
当需要有大量数据灌入或交换到数据库的时候,内存表空间可能不够。那么,需要创建磁盘表保存数据,当然,性能肯定不如内存表。
创建LogGroup
mysql> create logfile group lg_dbc_1 add undofile 'undo_dbc_1.log' initial_size 1024M undo_buffer_size 128M engine ndbcluster;
Query OK, 0 rows affected (10.29 sec)
lg_dbc_1
:logfile gourp名称
undo_dbc_1.log
:undofile文件名
1024M
:undo 初始化大小
128M
:undo 缓冲区大小
创建Tablespace
mysql> create tablespace ts_dbc_1 add datafile 'ts_dbc_1.dat' use logfile group lg_dbc_1 INITIAL_SIZE 40960M ENGINE NDBCLUSTER;
ts_dbc_1
:Tablespace名称
ts_dbc_1.dat
: Tablespace文件名称
lg_dbc_1
:LogGroup名称,写刚刚创建的LogGroup名称
40960M
:初始化Tablespace容量。
设置自增长
ALTER TABLESPACE ts_dbc_1 AUTOEXTEND_SIZE = 1G;
查询TableSpace
查询表空间用量:
mysql> SELECT TABLESPACE_NAME, FILE_NAME, EXTENT_SIZE*TOTAL_EXTENTS/1024/1024 AS TOTAL_MB,EXTENT_SIZE*TOTAL_EXTENTS/1024/1024 - EXTENT_SIZE*FREE_EXTENTS/1024/1024 as USED_MB,EXTENT_SIZE*FREE_EXTENTS/1024/1024 AS FREE_MB, EXTRA FROM information_schema.FILES WHERE FILE_TYPE="DATAFILE";
+-----------------+----------------+----------------+------------+----------------+-------+
| TABLESPACE_NAME | FILE_NAME | TOTAL_MB | USED_MB | FREE_MB | EXTRA |
+-----------------+----------------+----------------+------------+----------------+-------+
| ts_dbc_1 | ./ts_dbc_1.dat | 40960.00000000 | 0.00000000 | 40960.00000000 | NULL |
+-----------------+----------------+----------------+------------+----------------+-------+
1 row in set (0.00 sec)
查询LogFile调用量:
mysql> select * from ndbinfo.logspaces where log_type='DD-UNDO';
+---------+----------+--------+----------+------------+------+
| node_id | log_type | log_id | log_part | total | used |
+---------+----------+--------+----------+------------+------+
| 2 | DD-UNDO | 558 | 0 | 1072136240 | 480 |
| 3 | DD-UNDO | 558 | 0 | 1072136240 | 480 |
+---------+----------+--------+----------+------------+------+
2 rows in set (0.35 sec)
创建数据表
CREATE TABLE `db_name`.`table_name` (
`field_1` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE = ndbcluster CHARACTER SET = utf8mb4 ROW_FORMAT = DYNAMIC TABLESPACE = `ts_dbc_1` storage disk;