LoginSignup
22
17

More than 5 years have passed since last update.

MySQL5.7 から MySQL8.0にアップグレードしたらエラーが出る。

Last updated at Posted at 2018-06-20

備忘録

MySQL5.7からMySQL8.0にアップグレードしたあと、railsでrake db:migrateができなかったときの対処をまとめたもの

環境

macbook2016
os:10.12.6
ruby:2.4.3
rails:4.2.9

起こったこと

rails g scaffoldコマンドを実行してbundle exec rake db:migrateをしたら
以下のエラーが発生

rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: The user specified as a definer ('mysql.infoschema'@'localhost') does not exist: SHOW TABLES LIKE 'schema_migrations'

MySQLのユーザに権限がない... らしい。

MySQLのROOTユーザ権限で実行してみる。

datebase.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: 5
  host: localhost
  username: root
  password: root_user_password
  socket: /tmp/mysql.sock
bundle exec rake db:migrate

rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: The user specified as a definer ('mysql.infoschema'@'localhost') does not exist: SHOW TABLES LIKE 'schema_migrations'

結果は変わらず。

最終的にやったこと。

どうやらMySQL8.0に上がったことが原因らしい。
らしいことはわかったけど、アップグレードしたことでどこが変わったのかがわからないけれど、
以下のコマンドを実施することで解決。

mysql_upgrade -u root -p
Enter password: 
# rootユーザのパスワードを入力
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Upgrading system table data.
Checking system database.
mysql.columns_priv                                 OK
mysql.component                                    OK
mysql.db                                           OK
mysql.default_roles                                OK
mysql.engine_cost                                  OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.global_grants                                OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.password_history                             OK
mysql.plugin                                       OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.role_edges                                   OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Found outdated sys schema version 1.5.1.
Upgrading the sys schema.
Checking databases.
test_databese                                      OK
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.

もう一度、bundle exec rake db:migrateを実行してみる。

$ bundle exec rake db:migrate
== 20180620130245 CreateHoges: migrating ====================================
-- create_table(:hoges)
   -> 0.0173s
== 20180620130245 CreateHoges: migrated (0.0175s) ===========================

今度は成功!

原因がわからないのは気持ち悪い。
あとで調べる。でも、詳しい方がいらっしゃいて、教えてもらえたら嬉しいです。

22
17
1

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
22
17