9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mysql2::Error: Specified key was too long; max key length is 767 bytesを解決する

Last updated at Posted at 2019-02-03

現象

utf8mb4のカラム(name)に対してindexをはるときにエラーになってしまった:innocent:

...
-- add_index("posts", ["name"], {:name=>"name_index"})
[ERROR] Mysql2::Error: Specified key was too long; max key length is 767 bytes: CREATE  INDEX `name_index`  ON `posts` (`name`)
...

このあたりの記事を見ると、いろんな方法があるみたい :thinking:

対応

今回はcnfを書き換えてDBごと対応することにします。

cnfファイルの場所はmysql --help | grep my.cnfなどで調べます :point_up:

/usr/local/etc/my.cnf
...
innodb_file_format = Barracuda
innodb_file_per_table = 1
innodb_large_prefix

homebrewでインストールしたmysql@5.6を使っていたのでbrew servicesコマンドで再起動。

brew services restart mysql@5.6

以上です :hugging:

9
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?