my.cnf 中的不同设置导致“最大密钥长度为 1000 字节”错误
编辑:这可能是 5.0 特有的错误。 (我的版本是 5.0.83)。删除 innodb_log_file_size 设置可以解决该问题。这是完全有道理的。不是。
谷歌搜索发现 5.0 中存在一些类似但不相同的问题,这些问题后来得到了修复。
由于 my.cnf 中的“错误”设置,MySQL 5.0 上的此创建语句将给出“指定的密钥太长;最大密钥长度为 1000 字节”。
CREATE TABLE ReproduceTheProblem (
COLUMN_ONE varchar(200) character set utf8 default NULL,
COLUMN_TWO varchar(200) character set utf8 default NULL,
KEY ThisKeyBreaks(COLUMN_ONE, COLUMN_TWO)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
在尝试提高性能时,我的 my.cnf 设置表现良好,但出现“密钥太长”错误。我确实有 my.cnf 设置可以创建此键,但在将数据导入到另一个非常大的表中时,其性能非常糟糕。
有效但性能不佳的设置(并且由于我尝试拨入不同的设置而具有一些奇怪的值):
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 384M
max_allowed_packet = 1024M
table_cache = 256
max_sp_recursion_depth=255
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 30G
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
max_heap_table_size = 9900000
skip-federated
log-bin=mysql-bin
server-id = 1
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
性能良好但给我密钥长度错误的设置:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
max_allowed_packet = 200M
table_cache = 256
query_cache_type = 1
query_cache_limit = 20M
query_cache_size = 500M
long_query_time = 2
thread_cache_size = 1000
thread_concurrency = 4
innodb_thread_concurrency = 4
old_passwords = 1
max_connections = 1000
max_sp_recursion_depth = 255
server-id = 0
innodb_buffer_pool_size = 800M
innodb_additional_mem_pool_size = 50M
innodb_log_file_size=50M
innodb_log_buffer_size = 200M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout =50
[mysqldump]
quick
max_allowed_packet = 200M
[mysql]
no-auto-rehash
Edit: This may be a 5.0-specific bug. (I'm on 5.0.83). Removing the innodb_log_file_size setting gets rid of the problem. Which makes complete sense. Not.
Googling about finds a handful of similar, but not identical problems in 5.0 that were patched later.
With the "wrong" settings in my.cnf, this create statement on MySQL 5.0 will give me the "Specified key was too long; max key length is 1000 bytes".
CREATE TABLE ReproduceTheProblem (
COLUMN_ONE varchar(200) character set utf8 default NULL,
COLUMN_TWO varchar(200) character set utf8 default NULL,
KEY ThisKeyBreaks(COLUMN_ONE, COLUMN_TWO)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
In trying to improve performance, I arrived at my.cnf settings that perform well but get the "key was too long" error. I do have my.cnf settings that can create this key, but that perform terribly on importing data into a different, very large table.
The settings that work but perform badly (and which have some whacky values from my attempting to dial different settings in):
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 384M
max_allowed_packet = 1024M
table_cache = 256
max_sp_recursion_depth=255
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 30G
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
max_heap_table_size = 9900000
skip-federated
log-bin=mysql-bin
server-id = 1
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
The settings that perform well, but give me the key length error:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
socket = /tmp/mysql.sock
max_allowed_packet = 200M
table_cache = 256
query_cache_type = 1
query_cache_limit = 20M
query_cache_size = 500M
long_query_time = 2
thread_cache_size = 1000
thread_concurrency = 4
innodb_thread_concurrency = 4
old_passwords = 1
max_connections = 1000
max_sp_recursion_depth = 255
server-id = 0
innodb_buffer_pool_size = 800M
innodb_additional_mem_pool_size = 50M
innodb_log_file_size=50M
innodb_log_buffer_size = 200M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout =50
[mysqldump]
quick
max_allowed_packet = 200M
[mysql]
no-auto-rehash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的 my.cnf 与此没有太大关系,一定还有其他变量。
来自 InnoDB 表的限制:
我还注意到 bug 4541 表明限制为 1000 字节,并且没有计划简单地增加此限制。
在性能方面,像这样的大索引(和表)将会非常非常慢。我建议仅索引 varchar 的前缀而不是整个字符串。
I don't think your my.cnf has much to do with this, there must be some other variable.
From the Restrictions on InnoDB Tables:
I also note bug 4541 indicates a limit of 1000 bytes, and that there's no plans to simply increase this.
On the performance front, big indexes (and tables) like this will be really really slow. I'd suggest indexing only the prefix of the varchars rather than the whole string.