yumを使ったMySQL 5.7のインストール方法
これまで、CentOS 7に
・Apache 2.4.20
・PHP 7
のインストール方法をご紹介してきました。
今回は、前バージョンより3倍高速になった
MySQL 5.7のインストール方法を紹介します!
MySQLの特徴
・GPLライセンスで、GPL的に問題ない場合は商用でも無料で使える
・マルチユーザに対応していて、Webアプリケーションにも適用可能
・レンタルサーバーに多く導入されていて、データベース選びで悩んだ時とりあえずこれ
・YahooやGoogleなどのサイトでも使用されている
ということで、MySQLは、世界中でよく利用されています!
MySQLのインストール方法
では、MySQLをインストールしてみましょう!
1、MariaDBが入っていたらその削除
1 2 |
yum remove mariadb-libs rm -rf /var/lib/mysql/ |
※mysqlフォルダもしっかり削除しておかないと
rootユーザのパスワード設定で色々めんどうなことが起きる
2、RPMの準備
1 |
rpm -ivh http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm |
3、MySQL本体のインストール
1 |
yum install mysql-community-devel mysql-community-server |
4、my.cnfファイルの設定
1 2 3 4 5 6 7 8 |
vim /etc/my.cnf --(以下を最終行に追加)--- default_password_lifetime=0 log_timestamps=SYSTEM explicit_defaults_for_timestamp=TRUE skip-character-set-client-handshake character-set-server=utf8 |
5、MySQLの自動起動の設定
・MySQLの起動
1 |
systemctl start mysqld |
・MySQLの自動起動設定
1 |
systemctl enable mysqld |
6、MySQLの初期設定
・root の初期パスワードの確認
1 2 3 |
grep password /var/log/mysqld.log A temporary password is generated for root@localhost: xxxxxxyyyyyyyy |
・初期設定
1 |
mysql_secure_installation |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
Securing the MySQL server deployment. Enter password for user root: <初期パスワード> The existing password for the user account root has expired. Please set a new password. New password: <新しいパスワード> Re-enter new password: <新しいパスワード> Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : <空エンター> (略) Remove anonymous users? (Press y|Y for Yes, any other key for No) : y (略) Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y (略) Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y (略) Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! |
・rootユーザでログインできることを確認
1 |
mysql -u root -p |
7、ユーザの追加
・rootユーザでログイン
1 |
mysql -u root -p |
・新しくデータベースを作成する
1 |
CREATE DATABASE test; |
・新しくユーザーを作成する
1 |
CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'パスワードを入力'; |
・作成したユーザーに作成したデータベースの操作権限を付与する
1 |
GRANT ALL PRIVILEGES ON test.* TO 'test_user'@'localhost'; |
・設定を反映する
1 |
FLUSH PRIVILEGES; |
・作成したユーザでログイン
1 |
mysql -u test_user -p |
最後に
今回は、MySQL 5.7のインストール方法をご紹介しました。
yumを使っているので、
割りとお手軽にインストールできたのではないでしょうか!
その内、データベース操作のちょっとしたテクニックとかも
書いていきます。
デミ
最新記事 by デミ (全て見る)
- 【20分で完了】MacにDocker for Macのインストール - 2017/02/02
- 【2017年版】Web接客ツール9社を比較してみた - 2017/01/26
- 【昼休み中に完了!】Macで最新Ruby、Railsのインストールから画面表示まで - 2017/01/19