LoginSignup
2
3

More than 5 years have passed since last update.

【MySQL】エラー対応時のメモ集 -v0.1

Last updated at Posted at 2014-08-09

前回、MongoDBのエラー対応時のメモ集 -v0.1を作成しましたので、今回はそれのMySQL版を作りました。

こちらもエラーが出たら、追記していくつもりです。エラー集のようなものを完成形としています。

実際はこちらを見て解決している→公式リファレンス

0.更新履歴

日付 該当箇所 内容
2014.08.10 エラーログ 検索で引っかかるように全部のせてましたが、非常に見難いため、無駄なログを削除

1. railsにgem mysql2を入れ {$ rails s} or {$ rake db:migrate}時のエラー

エラーログ

/usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /usr//local/lib in PATH, mode 040757
/usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `require': dlopen(/usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0/mysql2-0.3.16/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0/mysql2-0.3.16/mysql2/mysql2.bundle
  Reason: image not found - /usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0/mysql2-0.3.16/mysql2/mysql2.bundle
        from /usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'

原因

・ Library not loaded: libmysqlclient.18.dylib (LoadError)

・ Reason: image not found - /usr/local/Cellar/ruby/2.1.1/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-13/2.1.0/mysql2-0.3.16/mysql2/mysql2.bundle

解決策

単純に、Loadできないライブラリにシンボリックリンクをはればおkです。

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

2. bin/rake db:migrate RAILS_ENV=development

エラーログ

undefined method `double' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007fb336642cd8>マイグレーションファイル.rb:6:in `block in change'

undefined method `int' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x007fb336642cd8>マイグレーションファイル.rb:7:in `block in change'

解決策

該当マイグレーションファイル
・double型をfloatにする
・int型をintegerにする

3. テーブルがないdoesn't exist

エラーログ

Mysql2::Error - Table 'スキーム名.テーブル名' doesn't exist:

解決策

・該当スキームに該当テーブルを作成する
・既にあるテーブル名に対して入れたい場合はモデル部分を編集

models/sample.rb
class Sample < ActiveRecord::Base
  self.table_name = "sample_test"
end

4. 範囲を超えた値を挿入した

エラーログ

Mysql2::Error - Out of range value for column 'sample_value' at row 1:

原因

・sample_valueの値に範囲を超えたものがinsertされたこと

解決策

・sample_valueの型を見なおして修正する
→私の場合はDecimal(8, 2)という型に123456.789という値をinsertしようとしていたのでDecimal(9, 3)にして無事解決です

5. 日付

昨日の日付に一致するレコードを取得する

select * from sample_table where sample_column = curdate() - 1;

6. insert時のエラー

c.j.b.ConnectionHandle - Database access problem. Killing off this connection and all remaining connections in the connection pool. SQL State = HY000

解決策

・AIがPKについていなくて落ちていたようだ。

ALTER TABLE `information_schema`.`INNODB_BUFFER_PAGE` 
CHANGE COLUMN `POOL_ID` `POOL_ID` BIGINT(21) UNSIGNED NOT NULL AUTO_INCREMENT ;

2
3
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
2
3