Specified key was too long; max key length is 3072 bytes


When running above statement to add unique index, following error happened.

[2018-03-28 11:38:24] [42000][1071] Specified key was too long; max key length is 3072 bytes


Table structure

So the above index key length is value(255*3), productId(4), productName(255*3), productSerialNumber(255*3), userPhone(255*3), userName(255*3), userId(8), type(255*3), statStartTime(8), statEndTime(8)

Total length is 255*6*3 + 4 + 8*3=4618 is greater than 3072 bytes.


Note that the charset used is UTF8, so every character will occupy 3 bytes.



Then change to following statement, and the error is fixed.


Another solution is to increase this 3072 bytes limit.

MySQL find all MyISAM tables

The information_schema table saves information about databases, tables, columns, indexes and triggers, etc.


To list all MyISAM tables, we can use following SQL


And to find MyISAM tables in database wordpress


Next filter them with a table prefix wp_

MySQL Auto Backup

First create a shell script which is used to backup database, here we named the script as mysql_backup.sh:

In above command, we use date command to generate current date, and use it as part of filename.

After that we need to make this file executable


To make this backup script run automatically, we should create a cronjob. Type following command to open cronjob editor

crontab -e

Write following text and save it

Above command means the cronjob will run at 0:00 everyday



Check MySQL case-insensitive query or table name

I tried to install Umbrao CMS, it supports MySQL database but it need MySQL to support case-insensitive query and table name.


Following is way to check whether case-insensitive query is supported:

show variables where variable_name='lower_case_table_names';

or check lower_case_table_names option in my.ini (MySQL configuration file)


If this option's value is set to 1, then case-insensitive query and table name is supported.