mysql-cluster采用磁盘文件存储表

虽然说是采用磁盘存储表,但是如果表中有主键或者索引就会将索引和该列的数据都存储到内存中,磁盘数据表的变长列将占用固定空间,对于每行来说,也就是占用最大空间。在磁盘数据表中,TEXT和BLOB的前256个字节存于内存,其他的存 放在磁盘上。磁盘数据表的每一行要在内存里面存放8个字节,以指向存放在磁盘上的数据。所以如果一行要存放在磁盘上数据少于8个字节,还不如都放 在内存里。数据节点重启时--initial选项并不移除磁盘数据文件,需要手工事先把他们干掉(如果原来就建有表空间,--initial参数会将表空间和表空间上的数据清除掉,切记!!)。 

如果采用磁盘存储,需要创建日志文件组以及undo日志文件,另外需要添加表空间,以及数据文件,创建格式如下:

1.创建日志文件组,并添加undo日志文件(如果创建时按以下语句执行报语法错误提示,可能是编码问题,运行命令set character_set_client=latin1; 原因:Character sets and binary log files. Currently, the ndb_apply_status and ndb_binlog_index tables are created using the latin1 (ASCII) character set. Because names of binary logs are recorded in this table, binary log files named using non-Latin characters are not referenced correctly in these tables. This is a known issue, which we are working to fix. (Bug #50226))

CREATE LOGFILE GROUP lg_2

ADD UNDOFILE 'undo_2.log'

INITIAL_SIZE 1024M

UNDO_BUFFER_SIZE 128M

ENGINE NDBCLUSTER

报错时可以用show errors查看错误内容,如:

mysql> create logfile group lg_2 add undofile 'undo_2.log' initial_size 1024M undo_buffer_size 128M engine ndbcluster;
ERROR 1528 (HY000): Failed to create LOGFILE GROUP
mysql> show errors;
+-------+------+---------------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------------+
| Error | 1296 | Got error 1504 'Out of logbuffer memory' from NDB |
| Error | 1528 | Failed to create LOGFILE GROUP |
+-------+------+---------------------------------------------------+
2 rows in set (0.00 sec)

可以 看出是由于超出logbuffer memory 大小原因导致的。

2.创建表空间,并添加数据文件

CREATE TABLESPACE ts_2  

  ADD DATAFILE 'data_2.dat'

  USE LOGFILE GROUP lg_2

  INITIAL_SIZE 409600M

ENGINE NDBCLUSTER;

3.删除日志文件组或者表空间的时候需要按顺序删除

只有在无表使用数据文件的时候才能删除数据文件

操作语法:

mysql> DROP TABLE dt_1;

只有在所有数据文件删除的情况下才能删除表空间

操作语法:

mysql> ALTER TABLESPACE ts_1

-> DROP DATAFILE 'data_2.dat'

-> ENGINE NDBCLUSTER;



mysql> ALTER TABLESPACE ts_1

-> DROP DATAFILE 'data_1.dat'

-> ENGINE NDBCLUSTER;



mysql> DROP TABLESPACE ts_1

-> ENGINE NDBCLUSTER;



只有使用UNDO logfile group的表空间都删除情况下才能删除undo logfile group

操作语法:

mysql> DROP LOGFILE GROUP lg_1

-> ENGINE NDBCLUSTER;

4.表空间的管理数据文件的管理

SELECT TABLESPACE_NAME, FILE_NAME, EXTENT_SIZE*TOTAL_EXTENTS/1024/1024 AS TOTAL_MB, EXTENT_SIZE*FREE_EXTENTS/1024/1024 AS FREE_MB, EXTRA FROM information_schema.FILES WHERE FILE_TYPE="DATAFILE";


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";



查看undo日志文件使用量信息
select * from ndbinfo.logspaces where log_type='DD-UNDO';

5.创建使用磁盘存储的表

create table Billinfo
(
bill_id int not null auto_increment,
ter_id int,
tax_reg_id int,
payer_id int,
tem_id int,
tran_serial_num int,
date_issued varchar(56),
time_issued varchar(56),
total_in_figures float,
discount_amount float,
amount_receivable float,
payment_type varchar(56),
cashier_num int,
primary key (bill_id)
) tablespace ts_1 storage disk engine=ndbcluster default charset=utf8;

你可能感兴趣的:(mysql,cluster)