I have two instances of MySQL database, let's say: TST and DEV.
TST:
mysql --version
mysql Ver 14.14 Distrib 5.6.40, for Linux (x86_64) using EditLine wrapper
DEV:
mysql --version
mysql Ver 14.14 Distrib 5.6.41, for Linux (x86_64) using EditLine wrapper
Almost the same version on both environments.
Databases on both instances have the same schema and the same data.
Problematic table has structure as below:
CREATE TABLE `searchItem` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`dataType` varchar(4) COLLATE utf8_unicode_ci NOT NULL,
`value` varchar(1024) COLLATE utf8_unicode_ci NOT NULL,
`creationTime` datetime NOT NULL,
`modificationTime` datetime NOT NULL,
`contentId` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_36F9E76573A18A3B` (`contentId`),
KEY `content_type` (`contentId`,`type`),
CONSTRAINT `FK_36F9E76573A18A3B` FOREIGN KEY (`contentId`) REFERENCES `content` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23518 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
And now I want to add index on column value(1024). I know that in my case index size limit is 255.
On DEV:
CREATE INDEX value_type ON searchItem (value, type);
Query OK, 0 rows affected, 1 warning (0.30 sec)
And now I have:
CREATE TABLE `searchItem` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`dataType` varchar(4) COLLATE utf8_unicode_ci NOT NULL,
`value` varchar(1024) COLLATE utf8_unicode_ci NOT NULL,
`creationTime` datetime NOT NULL,
`modificationTime` datetime NOT NULL,
`contentId` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_36F9E76573A18A3B` (`contentId`),
KEY `content_type` (`contentId`,`type`),
KEY `value_type` (`value`(255),`type`),
CONSTRAINT `FK_36F9E76573A18A3B` FOREIGN KEY (`contentId`) REFERENCES `content` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=23518 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
so it automatically cut index to maximum size (255) and this is expected behavior for me.
but on TST:
CREATE INDEX value_type ON searchItem (value, type);
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
I didn't find any differences in my.cnf file.
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[isamchk]
key_buffer_size = 16M
[mysqld]
basedir = /usr
bind-address = 0.0.0.0
character-set-server = utf8
datadir = /var/lib/mysql
default_storage_engine = InnoDB
expire_logs_days = 10
init-connect = SET NAMES utf8
innodb_file_per_table = 1
key_buffer_size = 16M
log-error = /var/log/mysql/error.log
max_allowed_packet = 128M
max_binlog_size = 100M
max_connections = 151
myisam_recover = BACKUP
pid-file = /var/run/mysqld/mysqld.pid
port = 3306
query_cache_limit = 1M
query_cache_size = 16M
skip-external-locking
socket = /var/run/mysqld/mysqld.sock
ssl = false
ssl-ca = /etc/mysql/cacert.pem
ssl-cert = /etc/mysql/server-cert.pem
ssl-key = /etc/mysql/server-key.pem
thread_cache_size = 8
thread_stack = 256K
tmpdir = /tmp
user = mysql
[mysqld_safe]
log-error = /var/log/mysql/error.log
nice = 0
socket = /var/run/mysqld/mysqld.sock
[mysqldump]
max_allowed_packet = 128M
quick
quote-names
EDIT:
Essentials of the question:
On DEV:
CREATE INDEX value_type ON searchItem (value, type);
Query OK, 0 rows affected, 1 warning (0.30 sec)
but on TST:
CREATE INDEX value_type ON searchItem (value, type);
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
The question is why it behaves differently on each environments? Is there any configuration parameter which can be responsible for this?