2014年10月21日火曜日

CentOS7にMySQL5.6をyumレポジトリからインストール

Christian Ditaputratama


そういえば、まだ、CentOS 7をあまりいじっていなかったので、とりあえず手始めにMySQLをインストールしてみました。

環境はAmazon EC2です。
AMIは、CentOS 7 (x86_64) with Updates HVMです。

AMI ID: CentOS 7 x86_64 (2014_09_29) EBS HVM-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-d2a117ba.2 (ami-89634988)
Instance Type: c3.xlarge
EBS: General Purpose (SSD)

* こちらのURLから最新のMySQLのyumレポジトリを探します。
http://dev.mysql.com/downloads/repo/yum/
Red Hat Enterprise Linux 7のDownloadリンクをクリック -> "No thanks, just start my download."のURLが最新です。

* MySQLのレポジトリをインストール。el7を選びます。
# rpm -i http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

* MySQLをインストール。
# yum install mysql-community-server mysql-community-devel

* MySQLサービスをスタート。/etc/init.d/mysqldじゃあなくなっているので注意です。
# service mysqld start

* MySQLのステータスをチェック。色々出てくるようになりました。
# service mysqld status -l
edirecting to /bin/systemctl status  -l mysqld.service
mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled)
   Active: active (running) since Wed 2014-10-22 01:18:38 UTC; 1min 43s ago
  Process: 1513 ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=0/SUCCESS)
  Process: 1454 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 1512 (mysqld_safe)
   CGroup: /system.slice/mysqld.service
           ├─1512 /bin/sh /usr/bin/mysqld_safe
           └─1652 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock

Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: Support MySQL by buying support/licenses at http://shop.mysql.com
Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: Note: new default config file not created.
Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: Please make sure your config file is current
Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: WARNING: Default config file /etc/my.cnf exists on the system
Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: This file will be read by default by the MySQL server
Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: If you do not want to use this, either remove it, or use the
Oct 22 01:18:37 ip-172-31-7-208 mysql-systemd-start[1454]: --defaults-file argument to mysqld_safe when starting the server
Oct 22 01:18:37 ip-172-31-7-208 mysqld_safe[1512]: 141022 01:18:37 mysqld_safe Logging to '/var/log/mysqld.log'.
Oct 22 01:18:37 ip-172-31-7-208 mysqld_safe[1512]: 141022 01:18:37 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Oct 22 01:18:38 ip-172-31-7-208 systemd[1]: Started MySQL Community Server.

* MySQLを初期化。
※ パスワードは便宜設定してください
# 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.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.<

Set root password? [Y/n] Y
New password:AAAAAA
Re-enter new password:AAAAAA
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.

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. 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 -uroot -pAAAAAA
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 14
Server version: 5.6.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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 "Hello World!";
+--------------+
| Hello World! |
+--------------+
| Hello World! |
+--------------+
1 row in set (0.00 sec)

ログインできました。
簡単ですね!