UbuntuでMySQL 5.7をインストールする方法

当ページのリンクには広告が含まれています。

この記事では、UbuntuにMySQL 5.7をインストールする方法を解説します。

Ubuntu 20.04から、インストールにはaptリポジトリの導入が必要になりました。一手間増えてしまいますが、基本的なインストール作業の流れはそれほど変わりありません。

目次

aptリポジトリの導入

STEP
公式サイトからaptリポジトリをダウンロードする
$ wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
STEP
パッケージをインストールする
$ sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
STEP
『ubuntu bionic』を選択する
STEP
『MySQL Server & Cluster (Currently selected: msql-8.0)』を選択する
STEP
『mysql-5.7』を選択する
STEP
aptキーを追加する
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467B942D3A79BD29
STEP
アップデートを実施する
$ sudo apt update
STEP
リポジトリが正常に追加されたか確認する
$ sudo apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.30-0ubuntu0.20.04.2
  Version table:
     8.0.30-0ubuntu0.20.04.2 500
        500 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
        500 http://jp.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages
     8.0.19-0ubuntu5 500
        500 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 Packages
        500 http://jp.archive.ubuntu.com/ubuntu focal/main i386 Packages
     5.7.39-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
STEP
必要なパッケージを一括でインストールする
sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
STEP
rootのパスワードを設定する
STEP
パスワードを再入力する
STEP
動作確認
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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>

管理コマンド

起動

$ systemctl start mysql

停止

$ systemctl stop mysql

再起動

$ systemctl restart mysql
この記事をシェア
  • URLをコピーしました!
目次