I have a databases with latin1 charachter set, I need to change tables character set to utf8, but I get error. the current character set is :
mysql> show variables like "%character%"; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ the table that I want to change the character set is :
mysql> describe spool; +------------+---------------------+------+-----+-------------------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+---------------------+------+-----+-------------------+----------------+ | username | varchar(250) | NO | MUL | NULL | | | xml | text | NO | | NULL | | | seq | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | created_at | timestamp | NO | | CURRENT_TIMESTAMP | | +------------+---------------------+------+-----+-------------------+----------------+ 4 rows in set (0.00 sec) when I want to change the character set I see bellow error :
mysql> ALTER TABLE spool CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes It's a company functioning database and I don't want to disturb the functionality, so I don't want to change the size of the varchar(250) type, I wonder if there is a solution to change this encoding.
mysql> show create table spool\G; *************************** 1. row *************************** Table: spool Create Table: CREATE TABLE `spool` ( `username` varchar(250) NOT NULL, `xml` text NOT NULL, `seq` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY `seq` (`seq`), KEY `i_despool` (`username`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=23490775 DEFAULT CHARSET=utf8
show create table spool;, it is more informative thandescribe.username(180)if applicable.