最新版のMySQLではなく、指定したバージョンのMySQLをインストールする手順について記載しています。
1.リポジトリの追加します。
Download MySQL Yum Repository ※2017/09 現在
https://dev.mysql.com/downloads/repo/yum/
sudo yum install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
実行結果
Loaded plugins: fastestmirror mysql57-community-release-el7-11.noarch.rpm | 25 kB 00:00 Examining /var/tmp/yum-root-WxGpfy/mysql57-community-release-el7-11.noarch.rpm: mysql57-community-release-el7-11.noarch Marking /var/tmp/yum-root-WxGpfy/mysql57-community-release-el7-11.noarch.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package mysql57-community-release.noarch 0:el7-11 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql57-community-release noarch el7-11 /mysql57-community-release-el7-11.noarch 31 k Transaction Summary ================================================================================ Install 1 Package Total size: 31 k Installed size: 31 k
確認を求められたら「y」を入力してEnter
Is this ok [y/d/N]: y
実行結果
Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mysql57-community-release-el7-11.noarch 1/1 Verifying : mysql57-community-release-el7-11.noarch 1/1 Installed: mysql57-community-release.noarch 0:el7-11 Complete!
最終行に「Complete!」と表示され手入れば成功です。
2.リポジトリを編集します。
設定ファイル:/etc/yum.repos.d/mysql-community.repo
sudo vi /etc/yum.repos.d/mysql-community.repo
例
5.6 をインストールするため、enabled=1
5.7 がデフォルトで 1 だったため、enabled=0
[mysql-connectors-community] name=MySQL Connectors Community baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-community] name=MySQL Tools Community baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.5 [mysql55-community] name=MySQL 5.5 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/ enabled=0 → 1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/ enabled=1 → 0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql80-community] name=MySQL 8.0 Community Server baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-preview] name=MySQL Tools Preview baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-cluster-7.5-community] name=MySQL Cluster 7.5 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-7.5-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-cluster-7.6-community] name=MySQL Cluster 7.6 Community baseurl=http://repo.mysql.com/yum/mysql-cluster-7.6-community/el/7/$basearch/ enabled=0 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
3.インストールを実行します。
次のコマンドを実行します。
sudo yum -y install mysql
4.バージョンを確認します。
次のコマンドを実行します。 ※mysqlにログインして実行。
select -version();
実行結果
+------------+ | -version() | +------------+ | -5.6 | +------------+ 1 row in set, 1 warning (0.00 sec)
1.MySQLの停止
/etc/init.d/mysqld stop
2.MySQLのアンインストール
sudo yum -y remove mysql-server sudo yum -y remove mysql
3.MySQLファイルの削除
rm -rf /var/lib/mysql
4.確認
rpm -qa | grep -i mysql
次のコマンドを実行しします。mysql -h RDSエンドポイント -P ポート番号 -u ユーザー名 -p データベース名実行結果
[ec2-user ~] ↓ mysql>