Database JUNKY

MySQL,MariaDBを中心としたブログです

OSSなDWH Infobrightの話 ② DWHの構築

前回、インストールのところまでは説明しました。 今回は、データベースの構築のところから説明したいと思います。なんで、ここか書かなかったかというと、MySQLと なんらかわらないからです、説明のし甲斐がない。。。。 (しかしながら操作方法がMySQLと変わらないのは、DWHをなじみやすくするのは非常に良いと考えだと思っております)

  1. まずコンソールがでるか確認する。 とりあえずコンソールがちゃんとでるか確認してみましょう。

    /usr/bin/mysql-ib

    Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.40-log build number (revision)=IB_3.3.1_r6997_7017(ice)Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

  2. データベースの一覧を表示する。 どんなデータベースが入っているか確認しよう mysql> show databases;
  3. +
    

    | Database           |

  4. +
    

    | information_schema | | BH_RSI_Repository  | | mysql              | | test               |

  5. +
    

    4 rows in set (0.04 sec)

  6. 上記1の操作で、ログインなしに接続できてしまったかと思うので、ちゃんと認証しないとログインできないような設定にしましょう。 デフォルトの設定で、パスワードが設定されていないことを確認する。 mysql> select user,host,password from mysql.user;
      • -+ | user | host      | password |
      • -+ 3 rows in set (0.02 sec)・パスワードを設定する。 mysql> set password for root@localhost=password('yourpassword'); Query OK, 0 rows affected (0.02 sec)mysql> set password for root@127.0.0.1=password('yourpassword); Query OK, 0 rows affected (0.00 sec)

mysql> exit

・パスワードなしでログイン出来ないことを確認する。

/usr/bin/mysql-ib

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

・パスワード付きでログインできることを確認する。

/usr/bin/mysql-ib -u root -h localhost -p

Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.40-log build number (revision)=IB_3.3.1_r6997_7017(ice)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> 4. データベースを作成する mysql> create database MYDWH; Query OK, 1 row affected (0.01 sec)mysql> show databases; + + | Database           | + + | information_schema | | BH_RSI_Repository  | | MYDWH              | | mysql              | | test               | + + 5 rows in set (0.00 sec)これでデータベースは完成 5. ユーザーを作成する。 rootで今後接続するのもなんかいやなので,analystというユーザーを作成して、上記、MYDWHを操作できるようにしたいと思います。 mysql> grant all privileges on MYDWH. to analyst@localhost identified by 'mypassword'; Query OK, 0 rows affected (0.02 sec) mysql> exit・リモートホストから接続できるようにする。 mysql> grant all privileges on MYDWH. to analyst@'%' identified by 'mypassword'; Query OK, 0 rows affected (0.00 sec)・analystで接続できるか確認

/usr/bin/mysql-ib -u analyst -h localhost -p

Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.1.40-log build number (revision)=IB_3.3.1_r6997_7017(ice)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

・データベースの一覧を確認する。 mysql> show databases; + + | Database           | + + | information_schema | | MYDWH              | | test               | + + 3 rows in set (0.00 sec)

・データベースを、MYDWHにスイッチする。 mysql> use MYDWH; Database changed

・テーブルの登録状況を確認する。 mysql> show tables; Empty set (0.01 sec)

・テーブルを作成する。 mysql> create table mytest(id int,detail char(10)); Query OK, 0 rows affected (0.05 sec)

mysql> show tables; + + | Tables_in_MYDWH | + + | mytest          | + + 1 row in set (0.00 sec)

・正常にアクセスできるか確認する。 mysql> select count() from mytest; + -+ | count() | + -+ |        0 | + -+ 1 row in set (0.07 sec) 6. テストデータを投入する。 上記で作成したテーブルにテストデータを導入してみたいと思います。(本格的なデータ投入はまた今度) ここで何を説明したいかというと、Infobright Community Edition(ICE)は、INSERT,UPDATE,DELETE,TRUNCATE等のDMLはサポートしていないため データを投入する手段が、LOAD以外にないからです。この証明をしたいだけの理由なので。ちょっと少ないですが、以下のテストデータを導入(LOAD)してみます。 /tmp/test.csv 1,"test1" 2,"test2" 3,"test3" 4,"test4" 5,"test5"

・あ、あれ? mysql> LOAD DATA INFILE '/tmp/test.csv' INTO TABLE mytest FIELDS TERMINATED BY ',' ENCLOSED BY '"'; ERROR 1045 (28000): Access denied for user 'analyst'@'localhost' (using password: YES) ・あれ?あれ? mysql> LOAD DATA LOCAL INFILE '/tmp/test.csv' INTO TABLE mytest FIELDS TERMINATED BY ',' ENCLOSED BY '"'; ERROR 1148 (42000): The used command is not allowed with this MySQL version ・どうも権限が関係しているようで、ロードがうまくいかないので、rootで接続、だれか教えてください。

/usr/bin/mysql-ib -u root -h localhost -p

Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 10 Server version: 5.1.40-log build number (revision)=IB_3.3.1_r6997_7017(ice) Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use MYDWH Database changed mysql> desc mytest; + + -+ + + + -+ | Field  | Type     | Null | Key | Default | Extra | + + -+ + + + -+ | id     | int(11)  | YES  |     | NULL    |       | | detail | char(10) | YES  |     | NULL    |       | + + -+ + + + -+ 2 rows in set (0.02 sec) ・再度、analyst でログインしなおし、結果を確認

/usr/bin/mysql-ib -u analyst -h localhost -p

Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.1.40-log build number (revision)=IB_3.3.1_r6997_7017(ice)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use MYDWH Database changed ・検索は行えるか? mysql> select * from mytest; + + + | id   | detail | + + + |    1 | test1  | |    2 | test2  | |    3 | test3  | |    4 | test4  | |    5 | test5  | + + + 5 rows in set (0.05 sec) ・INSERTは行えるか? mysql> insert into mytest values(1,"test"); ERROR 1031 (HY000): Table storage engine for 'mytest' doesn't have this option mysql> update mytest set id = 10 -> ; ERROR 1031 (HY000): Table storage engine for 'mytest' doesn't have this option mysql> delete from test; ERROR 1146 (42S02): Table 'MYDWH.test' doesn't exist mysql> delete from mytest; ERROR 1031 (HY000): Table storage engine for 'mytest' doesn't have this option mysql> truncate table mytest; ERROR 1031 (HY000): Table storage engine for 'mytest' doesn't have this option

とご覧の通り、何もできません。データをICEでは、データを再取得した場合は、テーブルのDROP&CREATE&LOADをするしか方法はなさそうです。