-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Key length #3
Comments
@nuxeh You can safely specify a shorter key length using the So if you are using, for example, a utf8 character set (default for MySQL), SELECT 767/(SELECT Maxlen FROM INFORMATION_SCHEMA.CHARACTER_SETS WHERE CHARACTER_SET_NAME='utf8');
+--------------------------------------------------------------------------------------------+
| 767/(SELECT Maxlen FROM INFORMATION_SCHEMA.CHARACTER_SETS WHERE CHARACTER_SET_NAME='utf8') |
+--------------------------------------------------------------------------------------------+
| 255.6667 |
+--------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) So, 255. Therefore, this will work: #
# Table schema for MySQL
#
CREATE TABLE urls (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
url VARCHAR(1000) NOT NULL,
created DATETIME NOT NULL,
accessed DATETIME,
hits INT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (id),
UNIQUE (url(255))
); (Note the 255 length specified for |
Worth noting I have not created a PR for this change as this limitation will I'm sure there's a way to use different CREATE commands based on MySQL versions Note too there will almost definitely be a performance impact when inserting |
When doing:
mysql -u root -p new_database < database.sql
I see the error:
ERROR 1071 (42000) at line 4: Specified key was too long; max key length is 767 bytes
using MariaDB.
This seems to be a limitation of the database itself, according to:
Would there be any way to work around this?
The text was updated successfully, but these errors were encountered: