LoginSignup
3
6

More than 5 years have passed since last update.

【MySQL】MySQL5.7→8.0にバージョンアップしたらDBが消えた件

Last updated at Posted at 2019-03-13

概要

MySQL5.7→8.0にバージョンアップするとMySQLは起動しているのにエラーでDBに接続できなくなってしまったときの対処法

経緯

ローカルのMySQLを5.7→8.0にバージョンアップして開発してて、PCの調子が悪くて再起動した後再度開発しようと思ったら下記エラーが出てDBにつながらなくなってしまった。

The user specified as a definer ('mysql.infoschema'@'localhost') does not exist

まずはそもそもMySQLが起動してないんじゃないかと思って確認したけど起動はしてる。

$ mysql.server status
 SUCCESS! MySQL running (684)

次にmysqlに入ってみて確認したら開発中のアプリと同じエラーが出ることを確認。

$ mysql -uroot -p
Server version: 8.0.15 Homebrew

mysql> show databases;
ERROR 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost') does not exist

対処方法

MySQLのバージョンを5.7→8.0に上げると色々問題あることを思い出してググったところ解決法を発見。
[Laradock][MySQL8] ユーザー権限がなく、データベースを操作できない時

まずはMySQLからログアウト。

mysql> exit
Bye

下記コマンドを実行。

$ mysql_upgrade -uroot -p
Enter password:
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.
sys.sys_config                                     OK
Upgrade process completed successfully.
Checking if update is needed.

MySQLに接続して確認。

$ mysql -uroot -p
Server version: 8.0.15 Homebrew

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

開発中のアプリからも接続できることを確認して無事解決。

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