MySQL 5.7.28→MySQL 8.0.19(最新バージョン)への変更方法についてまとめています。
OSはDevianまたはUbuntuを前提に解説しています。


MySQLのバージョン確認 (5.7.28)
MySQLの現在のバージョンを確認します。
- # mysql -u root -pmy-secret-pw
- mysql: [Warning] Using a password on the command line interface can be insecure.
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3
- Server version: 5.7.28 MySQL Community Server (GPL)
- Copyright (c) 2000, 2019, 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> select version();
- +-----------+
- | version() |
- +-----------+
- | 5.7.28 |
- +-----------+
- 1 row in set (0.00 sec)
【関連記事】
▶MySQLのバージョン確認確認方法 ServerとClientバージョンを調べるには?
バージョンアップ前に、必ずデータベースのバックアップを取っておきましょう。
【関連記事】
▶MySQLのデータバックアップなら専用コマンドのmysqldumpを
また、バージョンアップ前にMySQLサービスを停止しておきます。
MySQL 最新バージョン(8.0.19)のインストール
MySQLリポジトリ追加用のツールをインストールします。
- # wget https://dev.mysql.com/get/mysql-apt-config_0.8.14-1_all.deb
ダウンロードするファイルは、以下のページの最新版を選んでください。
参考)MySQL :: Download MySQL APT Repository
リポジトリ追加ツールをインストールします。
【関連記事】
▶MySQL 8.0をUbuntu 18.04にインストール リポジトリの登録方法は?
- # dpkg -i ./mysql-apt-config_0.8.14-1_all.deb
- (Reading database ... 10289 files and directories currently installed.)
- Preparing to unpack .../mysql-apt-config_0.8.14-1_all.deb ...
- Unpacking mysql-apt-config (0.8.14-1) ...
- Setting up mysql-apt-config (0.8.14-1) ...
- debconf: unable to initialize frontend: Dialog
- debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
- debconf: falling back to frontend: Readline
- Configuring mysql-apt-config
- ----------------------------
- MySQL APT Repo features MySQL Server along with a variety of MySQL components. You may select the appropriate product to choose the
- version that you wish to receive.
- Once you are satisfied with the configuration then select last option 'Ok' to save the configuration, then run 'apt-get update' to load
- package list. Advanced users can always change the configurations later, depending on their own needs.
インストール時に「lsb-release is not installed」というエラーが出力された場合は、apt-get install lsb-releaseにて、lsb-releaseコマンドをインストールしてください。
- # dpkg -i ./mysql-apt-config_0.8.14-1_all.deb
- Selecting previously unselected package mysql-apt-config.
- dpkg: regarding .../mysql-apt-config_0.8.14-1_all.deb containing mysql-apt-config, pre-dependency problem:
- mysql-apt-config pre-depends on lsb-release
- lsb-release is not installed.
- dpkg: error processing archive ./mysql-apt-config_0.8.14-1_all.deb (--install):
- pre-dependency problem - not installing mysql-apt-config
- Errors were encountered while processing:
- ./mysql-apt-config_0.8.14-1_all.deb
入力を求められる箇所は、以下のように入力します。
- 1. MySQL Server & Cluster (Currently selected: mysql-5.7) 3. MySQL Preview Packages (Currently selected: Disabled)
- 2. MySQL Tools & Connectors (Currently selected: Enabled) 4. Ok
- Which MySQL product do you wish to configure? 1
- This configuration program has determined that mysql-5.7 is configured on your system, and has highlighted the most appropriate
- repository package. If you are not sure which version to install, do not change the auto-selected version. Advanced users can always
- change the version as needed later. Note that MySQL Cluster also contains MySQL Server.
- 1. mysql-5.6 2. mysql-5.7 3. mysql-8.0 4. mysql-cluster-7.5 5. mysql-cluster-7.6 6. mysql-cluster-8.0 7. None
- Which server version do you wish to receive? 3
- :
- :
- 1. MySQL Server & Cluster (Currently selected: mysql-8.0) 3. MySQL Preview Packages (Currently selected: Disabled)
- 2. MySQL Tools & Connectors (Currently selected: Enabled) 4. Ok
- Which MySQL product do you wish to configure? 4
- Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
- OK
上記で入力したバージョンのMySQLが、次回にapt-get install実行時にインストールされます。
apt-get updateで、リポジトリ情報を更新します。
- # apt-get update
- Ign:1 http://deb.debian.org/debian stretch InRelease
- Hit:2 http://deb.debian.org/debian stretch-updates InRelease
- Hit:3 http://repo.mysql.com/apt/debian stretch InRelease
- :
- :
以下のコマンドで、先ほど指定したバージョンのMySQL(8.0)がインストールされます。
- # apt-get install mysql-server
- Reading package lists... Done
- Building dependency tree
- Reading state information... Done
- The following package was automatically installed and is no longer required:
- libatomic1
- :
- :
MySQLを起動して、バージョンを確認してみましょう。
- # mysqld --version
- /usr/sbin/mysqld Ver 8.0.19 for Linux on x86_64 (MySQL Community Server - GPL)
念のため、データベースに接続してバージョンを確認します。
- # mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 8
- Server version: 8.0.19 MySQL Community Server - GPL
- Copyright (c) 2000, 2020, 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> select version();
- +-----------+
- | version() |
- +-----------+
- | 8.0.19 |
- +-----------+
- 1 row in set (0.00 sec)
MySQLのバージョンが5.7.28→MySQL 8.0.19にアップグレードできました。


まとめ

- バージョンアップ前に、必ずデータベースのバックアップを取得
- MySQL 8.0にバージョンアップするには、リポジトリツールをインストールしてインストールバージョンMySQL8.0を指定
- バージョンアップ後は、バージョンを確認する。