CREATE TABLE wp_locations (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`city` VARCHAR(255) NOT NULL,
`name` VARCHAR(255) NOT NULL,
CONSTRAINT `city_name` UNIQUE (`city`, `name`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
I got an sql error '#1071 - Specified key was too long; max key length is 767 bytes'
What am I doing wrong?
SQL keyword errors occur when one of the words that the SQL query language reserves for its commands and clauses is misspelled. For example, writing “UPDTE” instead of “UPDATE” will produce this type of error.
The cause of these problems can vary from file system corruption, underlying hardware system issues, driver issues, corrupted pages in memory, or problems with the SQL Server Engine.
The name of the object that could not be resolved. Possible reasons for this error include: The specified name is not a column of any of the source or target tables or views of the statement.
MySQL always reserves the max amount for a UTF8
field which is 4 bytes so with 255 + 255
with your DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
; you are over the 767 max key length limit.
You can only reduce the single varchar length or don't use a composite key.
I had the same exact issue. I've added these lines to a new conifg file in /etc/my.conf.d directory named umb4-support.cnf
[mysqld]
innodb_large_prefix=true
innodb_file_format=barracuda
innodb_file_per_table=true
After restarting the maria db service, my import scripts ran without this issue. Godspeed!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With