Contents
1.MySQLのダウンロード
今まではソースをコンパイルしてインストールしてきましたが、mysqlはyumでmysql5.7をインストールします。
CentOS7.6をインストールしますとmariaDB(MySQL互換のDB)がインストールされる場合がありますので、まずこれが残ったままだと、これからインストールするMySQLと競合するので、まずは削除しておきます。
1.1 mariaDBの削除
mariaDBが存在するか確認
1 2 |
# rpm -qa | grep maria mariadb-libs-5.5.60-1.el7_5.x86_64 |
mariaDBの削除
1 2 |
# yum remove mariadb-libs # rm -rf /var/lib/mysql/ |
1.2 MySQL公式リポジトリの追加と設定
①MySQLの5.6以降をインストールするためには、まずMySQL公式サイトからリポジトリをインストールします。
RHEL7系用のパッケージをダウンロードし、直接インストール
1 |
# yum install https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm |
②リポジトリが追加されたか確認します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# yum repolist all | grep mysql mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community 無効 mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - So 無効 mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community 無効 mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - So 無効 mysql-connectors-community/x86_64 MySQL Connectors Community 有効 mysql-connectors-community-source MySQL Connectors Community - Sou 無効 mysql-tools-community/x86_64 MySQL Tools Community 有効 mysql-tools-community-source MySQL Tools Community - Source 無効 mysql-tools-preview/x86_64 MySQL Tools Preview 無効 mysql-tools-preview-source MySQL Tools Preview - Source 無効 mysql55-community/x86_64 MySQL 5.5 Community Server 無効 mysql55-community-source MySQL 5.5 Community Server - Sou 無効 mysql56-community/x86_64 MySQL 5.6 Community Server 無効 mysql56-community-source MySQL 5.6 Community Server - Sou 無効 mysql57-community/x86_64 MySQL 5.7 Community Server 無効 mysql57-community-source MySQL 5.7 Community Server - Sou 無効 mysql80-community/x86_64 MySQL 8.0 Community Server 有効 mysql80-community-source MySQL 8.0 Community Server - Sou 無効 |
③このままではMySQL8.0がインストールされてしまうので、5.7がインストールされるように設定を変更します。
設定を変更するためにはyumの設定変更用のyum-utilsパッケージが必要なので、インストールされていない場合はインストールする。
1 2 |
# yum list installed | grep yum-utils # yum -y install yum-utils |
MySQL8.0を無効化
1 |
# yum-config-manager --disable mysql80-community |
MySQL5.7を有効化
1 |
# yum-config-manager --enable mysql57-community |
2.MySQLのインストール
2.1 パッケージのバージョンを確認します。
パッケージの情報がずらずらっと表示されますが、バージョンが5.7.xxになっていればOK。インストールします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# yum info mysql-community-server …(略)… 名前 : mysql-community-server アーキテクチャー : x86_64 バージョン : 5.7.24 リリース : 2.el6 容量 : *** M リポジトリー : installed 提供元リポジトリー : mysql57-community 要約 : A very fast and reliable SQL database server URL : http://www.mysql.com/ ライセンス : Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field. 説明 : …(略)… |
2.2 インストール
インストール
1 |
# yum -y install mysql-community-server |
インストールされたらバージョンを確認
1 2 |
# mysqld --version mysqld Ver 5.7.24 for Linux on x86_64 (MySQL Community Server (GPL)) |
3.Mysqlの起動/停止/自動起動設定
1 2 3 4 5 6 |
# systemctl start mysqld ← 起動 # systemctl stop mysqld ← 停止 # systemctl status mysqld ← ステータス確認 # systemctl restart mysqld ← 再起動 # systemctl enable mysqld ← 自動起動 ON # systemctl start mysqld |
自動起動になっているか確認する
1 2 3 |
# systemctl is-enabled mysqld mysqld.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig mysqld --level=5 enabled |
enabledになっていれば自動起動 ONに設定されている。
chkconfigで確認
1 2 3 |
# chkconfig --list mysqld ← 自動起動設定の確認 mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off 2~5がonになっていれば自動起動 ONに設定されている |
4.Mysqlの初期設定
4.1 root ユーザーの初期パスワードを知る
MySQL 5.7 では、初回起動と同時に root ユーザーにランダムな文字列がパスワードとして設定されます。 初期パスワードは MySQL のログファイルに出力されています。 ログファイルは/var/log/mysqld.log です。 ログを開くと次のようにパスワードが記載されています。
1 2 3 |
# vi /var/log/mysqld.log [Note] A temporary password is generated for root@localhost: ??XX;BB6Y ??XX;BB6Y ランダムな初期パスワード |
4.2 root ユーザーのパスワードを設定する
①mysql_secure_installation でrootパスワードを違うものに変更する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. # 現在のmysqlのrootパスワードを入力 Enter current password for root (enter for none):??XX;BB6Y OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. # rootパスワードを設定しますか? Set root password? [Y/n] y New password:任意のパスワード Re-enter new password:再度同じパスワード Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. # 匿名ユーザーを削除しますか? Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. # リモートでのrootログインを拒否しますか? Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. # テスト用データベースを削除しますか? Remove test database and access to it? [Y/n] y - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. # 今すぐFLUSH PRIVILEGESしますか? Reload privilege tables now? [Y/n] y ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up... |
②以降、MySQLにログインするには
1 2 |
# mysql -u root -p password ; |