LoginSignup
17
11

More than 5 years have passed since last update.

MySQL5.1→5.7へアップグレード

Last updated at Posted at 2016-08-20

各種バージョン

バージョン
OS CentOS 6.8
MySQL(アップグレード前) 5.1.73
MySQL(アップグレード後) 5.7.14

RPMリポジトリの追加

最新版のリポジトリURLは下記URLを参照。

$sudo rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el6-8.noarch.rpm

MySQLファイルのバックアップ

$sudo cp -aR /var/lib/mysql/ /var/lib/mysql_bk/

MySQLの停止

$sudo service mysqld stop

MySQLのアップグレード

$sudo yum update mysql-server

テーブルのアップグレード

MySQLを起動後に下記のmysql_upgradeコマンドを入力することでテーブルを修正してくれるのですが、
私の環境の場合、下記のエラーが発生し、MySQLが起動できませんでした。

[ERROR] Fatal error: mysql.user table is damaged. Please run mysql_upgrade.
[ERROR] Aborting

そのため、セーフモード(ユーザ認証のパスワードなし)で起動し、mysql_upgradeコマンドを実行しています。

下記のコマンドで、MySQLをセーフモードで起動する。

$/usr/bin/mysqld_safe --skip-grant-tables &

セーフモードで起動後、テーブルをアップグレードする

$mysql_upgrade -u root -p

以下のメッセージが表示されれば正常に完了

Upgrade process completed successfully.
Checking if update is needed.

my.cnfに下記を追加する。
mysql5.6以降は暗黙のデフォルト値としてTIMESTAMP型を使用すること非推奨になっているため、下記設定をしないとWARNINGが発生する。

/etc/my.cnf
[mysqld]
explicit_defaults_for_timestamp = true

MySQLを再起動する

$sudo service mysqld restart

MySQLにログインできるか確認

$mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.7.14 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
17
11
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
17
11