2014年7月21日月曜日

MySQL5.6をrpmでインストールしてみる

MySQLのインストールをやってみた。

■環境
 ・CentOS 6.4(x64) on VirtualBox
 ・MySQL 5.6.19

1.rpmの入手
  このサイトからrpmをする。入手できるモジュールは以下の通り。
  bundleパッケージには以下のモジュールが含まれている。
serverMySQLサーバー本体
client各種クライアントツール
develC API開発用ヘッダファイルと静的リンクライブラリ
sharedC API共有ライブラリ
shared-compat古いバージョンの共有ライブラリ
embeddedlibmysqld(サーバーを直接動作させるライブラリ)
testMySQLテストスイート
 # mkdir /tmp/mysql;cd /tmp/mysql
 # wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.19-1.el6.x86_64.rpm-bundle.tar
 # tar xvf MySQL-5.6.19-1.el6.x86_64.rpm-bundle.tar
 # ls
 MySQL-5.6.19-1.el6.x86_64.rpm-bundle.tar  MySQL-server-5.6.19-1.el6.x86_64.rpm
 MySQL-client-5.6.19-1.el6.x86_64.rpm      MySQL-shared-5.6.19-1.el6.x86_64.rpm
 MySQL-devel-5.6.19-1.el6.x86_64.rpm       MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm
 MySQL-embedded-5.6.19-1.el6.x86_64.rpm    MySQL-test-5.6.19-1.el6.x86_64.rpm

2.インストールをする
 続いてインストール。
 # rpm -ihv MySQL-server-5.6.19-1.el6.x86_64.rpm
 Preparing...                ########################################### [100%]
        file /usr/share/mysql/czech/errmsg.sys from install of MySQL-server-5.6.19-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.66-2.el6_3.x86_64
        file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-5.6.19-1.el6.x86_64 conflicts with file from package mysql-libs-5.1.66-2.el6_3.x86_64
        file /usr/share/mysql/dutch/errmsg.sys from install of MySQL-server-5.6.19-1.el6.x86_64 conflicts with file from
 ・
 ・
 何やらエラーでまくり。記載通り競合しているらしいので、調べたら、
  MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm
 を先にインストールし、以前のバージョン依存性を壊すことなく、ライブラリをVerUPができるらしい。
 # rpm -ivh MySQL-shared-compat-5.6.19-1.el6.x86_64.rpm
 Preparing...                ########################################### [100%]
    1:MySQL-shared-compat    ########################################### [100%]

 # rpm -e mysql-libs-5.1.66-2.el6_3.x86_64

 # rpm -ihv MySQL-server-5.6.19-1.el6.x86_64.rpm
 Preparing...                ########################################### [100%]
    1:MySQL-server           ########################################### [100%]
 2014-07-20 12:19:09 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
 2014-07-20 12:19:09 2447 [Note] InnoDB: Using atomics to ref count buffer pool pages
 <中略>
  A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER !
 You will find that password in '/root/.mysql_secret'.

 You must change that password on your first connect,
 no other statement but 'SET PASSWORD' will be accepted.
 See the manual for the semantics of the 'password expired' flag.

 Also, the account for the anonymous user has been removed.

 In addition, you can run:

   /usr/bin/mysql_secure_installation

 which will also give you the option of removing the test database.
 This is strongly recommended for production servers.

 See the manual for more instructions.

 Please report any problems at http://bugs.mysql.com/

 The latest information about MySQL is available on the web at

   http://www.mysql.com

 Support MySQL by buying support/licenses at http://shop.mysql.com

 New default config file was created as /usr/my.cnf and
 will be used by default by the server when you start it.
 You may edit this file to change server settings

 #
 成功。続いて残りのパッケージも入れる。今回は、clientとtestだけ入れてみる。
 # rpm -ivh MySQL-client-5.6.19-1.el6.x86_64.rpm MySQL-test-5.6.19-1.el6.x86_64.rpm
 Preparing...                ########################################### [100%]
    1:MySQL-client           ########################################### [ 50%]
    2:MySQL-test             ########################################### [100%]

 # rpm -qa | grep MySQL
 MySQL-server-5.6.19-1.el6.x86_64
 MySQL-test-5.6.19-1.el6.x86_64
 MySQL-shared-compat-5.6.19-1.el6.x86_64
 MySQL-client-5.6.19-1.el6.x86_64
 インストールは問題なし。で、インストールの時に出てきた初期設定シェル(mysql_secure_installation)
 を実行する。このシェルは以下の設定を実施してくれるもの。

 ・rootパスワードの変更
 ・rootのリモートホストからのログイン禁止(localhostのみ)
 ・匿名ユーザーの削除
 ・testデータベースの削除
 # /etc/init.d/mysql start
 Starting MySQL. SUCCESS!

 # /usr/bin/mysql_secure_installation

 <中略> 

 Thanks for using MySQL!

 Cleaning up...
 #
 rootのパスワードは、インストールしてから変更していなければ、/root/.mysql_secret
 に記載されている。それ以外は全てyで回答。で最後に稼働確認。
 # mysqladmin -u root -p ping
 Enter password:
 mysqld is alive

 # mysql -u root -p
 Enter password:
 Welcome to the MySQL monitor.  Commands end with ; or \g.
 Your MySQL connection id is 19
 Server version: 5.6.19 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> show databases;
 +--------------------+
 | Database           |
 +--------------------+
 | information_schema |
 | mysql              |
 | performance_schema |
 +--------------------+
 3 rows in set (0.00 sec)

 mysql> exit;
 Bye
 #
 # ps ax|grep [m]ysqld
  3513 pts/0    S      0:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/wp1.hayachi617.jp.pid
  3618 pts/0    Sl     0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/wp1.hayachi617.jp.err --pid-file=/var/lib/mysql/wp1.hayachi617.jp.pid
 #
 無事接続もできるし、testデータもないですね。ログを見てみると、
 #cat /var/lib/mysql/wp1.hayachi617.jp.err
 140720 13:26:28 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
 2014-07-20 13:26:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
 <略>
 というWarningが出ていた。引数もなんなので、/etc/my.cnfに記載する。
 [mysqld]
 explicit_defaults_for_timestamp=true
 このオプションは、5.6からできたオプション。timestamp型のデフォルトの属性を
 明示的に指定をするかどうか?の指定をするboolean。デフォルトはfalse(0)。5.5
 以前と合わせるのであれば、falseにしておく。がデフォルト属性が突如変更になる
 可能性もあり、本来は明示的に指定したほうがよさそう。
 
 explicit_defaults_for_timestamp=trueのとき時
 mysql>  show global variables like 'explicit_defaults_for_timestamp';
 +---------------------------------+-------+
 | Variable_name                   | Value |
 +---------------------------------+-------+
 | explicit_defaults_for_timestamp | ON    |
 +---------------------------------+-------+
 1 row in set (0.01 sec)

 mysql>
 mysql> create database test;
 Query OK, 1 row affected (0.00 sec)

 mysql> create table test (update_time timestamp) ENGINE=InnoDB;
 Query OK, 0 rows affected (0.06 sec)

 mysql> show create table test\G
 *************************** 1. row ***************************
        Table: test
 Create Table: CREATE TABLE `test` (
   `update_time` timestamp NULL DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
 1 row in set (0.00 sec)
 特に属性はついていないようですね。次に、、

 explicit_defaults_for_timestamp=falseのとき時
 mysql> show global variables like 'explicit_defaults_for_timestamp';
 +---------------------------------+-------+
 | Variable_name                   | Value |
 +---------------------------------+-------+
 | explicit_defaults_for_timestamp | OFF   |
 +---------------------------------+-------+
 1 row in set (0.01 sec)

 mysql>
 mysql> create database test;
 Query OK, 1 row affected (0.00 sec)

 mysql> create table test (update_time timestamp) ENGINE=InnoDB;
 Query OK, 0 rows affected (0.06 sec)

 mysql> show create table test\G
 *************************** 1. row ***************************
        Table: test
 Create Table: CREATE TABLE `test` (
   `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
 1 row in set (0.00 sec)
 いろいろ属性が付いてますね。必要であれば、これを明示的に記載した
 ほうがよさそうですね。

 最後に自動起動するようにしておく。
 # chkconfig mysql on
 # chkconfig|grep mysql
 mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
3.その他の設定
 その他にもありそうな設定を/etc/my.cnfに入れてみる。
 [mysqld]
 explicit_defaults_for_timestamp=true (*1)
 character-set-server=utf8            (*2)
 datadir=/var/lib/mysql               (*3)

 [mysql]
 default-character-set=utf8           (*4)

(*1) さっきの件
(*2) MySQLサーバー側のデフォルト文字コードの設定。設定後にDBの情報をのぞいてみると、、
 mysql> show variables like 'char%';
 +--------------------------+----------------------------+
 | Variable_name            | Value                      |
 +--------------------------+----------------------------+
 | character_set_client     | utf8                       |
 | character_set_connection | utf8                       |
 | character_set_database   | utf8                       |
 | character_set_filesystem | binary                     |
 | character_set_results    | utf8                       |
 | character_set_server     | utf8                       |
 | character_set_system     | utf8                       |
 | character_sets_dir       | /usr/share/mysql/charsets/ |
 +--------------------------+----------------------------+
 8 rows in set (0.00 sec)
無事変更されていることを確認。
(*3) データファイルの配置場所の指定
(*4) MySQLクライアント側のデフォルト文字コードの設定

0 件のコメント:

コメントを投稿