简体   繁体   English

mysql流利的nhibernate问题nvarchar

[英]mysql fluent nhibernate issue nvarchar

I have switched from sql server 2005 to mysql which was not really a problem. 我已经从sql server 2005切换到mysql,这不是一个真正的问题。

I have a slight issue with (n)varchar which exist in sql server. 我在sql server中存在(n)varchar的一个小问题。 Usually I have used: 通常我用过:

mapping.Map(x => x.bla).Length(10000);

to set bla to nvarchar(max). 将bla设置为nvarchar(max)。 does this work in mysql? 这在mysql中有效吗? I believe there is no nvarchar in mysql and you have to use something like this: 我相信mysql中没有nvarchar,你必须使用这样的东西:

alter table sometable modify bla VARCHAR(21844) CHARACTER SET utf8

to update an existing column to 'nvarchar(max)'. 将现有列更新为“nvarchar(max)”。 Is this correct because I am getting: 这是正确的,因为我得到:

"Row size too large. The maximum row size for the used table type" “行大小太大。使用的表类型的最大行大小”

If I am using: 如果我正在使用:

alter table sometable modify bla VARCHAR(1000) CHARACTER SET utf8

things work but I am not sure whether this achieves 'nvarchar(max)' in mysql. 事情有效,但我不确定这是否在mysql中实现'nvarchar(max)'。

As explained in the manual : 手册所述

Every table (regardless of storage engine) has a maximum row size of 65,535 bytes. 每个表(无论存储引擎如何)的最大行大小为65,535字节。 Storage engines may place additional constraints on this limit, reducing the effective maximum row size. 存储引擎可能会对此限制设置其他限制,从而减少有效的最大行大小。

The maximum row size constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size. 最大行大小限制列的数量(可能是大小),因为所有列的总长度不能超过此大小。 For example, utf8 characters require up to three bytes per character, so for a CHAR(255) CHARACTER SET utf8 column, the server must allocate 255 × 3 = 765 bytes per value. 例如, utf8字符每个字符最多需要三个字节,因此对于CHAR(255) CHARACTER SET utf8列,服务器必须为每个值分配255×3 = 765个字节。 Consequently, a table cannot contain more than 65,535 / 765 = 85 such columns. 因此,一个表不能包含超过65,535/765 = 85个这样的列。

Storage for variable-length columns includes length bytes, which are assessed against the row size. 可变长度列的存储包括长度字节,其根据行大小进行评估。 For example, a VARCHAR(255) CHARACTER SET utf8 column takes two bytes to store the length of the value, so each value can take up to 767 bytes. 例如, VARCHAR(255) CHARACTER SET utf8列需要两个字节来存储值的长度,因此每个值最多可占用767个字节。

You must therefore consider what other columns exist in your table and calculate the maximum size available for this VARCHAR . 因此,您必须考虑表中存在的其他列,并计算此VARCHAR可用的最大大小。

However, if you require space for long text values, why not use the TEXT data types, which are not constrained by this limit (except for the 9 to 12 bytes they contribute toward it)? 但是,如果您需要长文本值的空间,为什么不使用不受此限制约束的TEXT数据类型(除了它们为它提供的9到12个字节)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM