Posts tagged ‘MySQL’

Installation of Redmine 2

Installation of Redmineの続きです。

Redmineでもデータベースを使用しますが、今回はMySQLを使用したいと思います。
Redmineを展開したディレクトリの中にconfig/database.yml.exambleというファイルがあるので、それを「database.yml」にリネームして使用することにします。
まずはDatabaseを作成します。
MySQLのクライアントを起動して、「redmine」という名前のデータベースを作成します。

mysql> create database redmine;
Query OK, 1 row affected (0.04 sec)

ついでに、じゃないですけど、redmineを使用するユーザーを作成します。
“set password”でちゃんとしたパスワードを設定しましょう。(例ではnewpasswordにしています。あくまで例です。)

mysql> grant create,select,insert,delete,update on redmine.* to redmine@localhost identified by 'password';
Query OK, 0 rows affected (0.08 sec)
 
mysql> set password for 'redmine'@'localhost' = password('newpassword');
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)

作成したユーザーでログインしてみます。

mysql> \q
Bye
[root@blackhole config]# mysql -u redmine -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8282
Server version: 5.0.45 Source distribution
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

一応これでOKなはず。MySQLを使用するやつはCreate Table権限が必要な場合が多いですよね。あんまり業務アプリケーションではALTER権限自体与える場合が少ないですが。

そして先ほどのdatabase.yml(ymlのyってなんだろ?)の「production」のセクションを先ほど設定した内容に書き換えます。

production:
  adapter: mysql
  database: redmine
  host: localhost
  username: redmine
  password: newpassword
  encoding: utf8

別に記載しておきますが、使用しているMySQLの一時ファイル(ソケット用?)が、 標準(/tmp/mysql.sock)と違うところに作成されているようでした。

# mysqladmin -p variables | grep socket
Enter password:
| socket                          | /var/lib/mysql/mysql.sock                               |

「/var/lib/mysql/mysql.sock」に作成されているようなので、この設定をconfig/database.ymlに追記します。

 socket: /var/lib/mysql/mysql.sock

そしてインストールのコマンドを入力します。rakeというらしい、(makeのruby版だからでしょうか?)

<code># rake db:migrate RAILS_ENV="production"
(in /www/labs/redmine-0.8.5)</code>
rake aborted!
Mysql::Error: #42000INDEX command denied to user 'redmine'@'localhost' for table 'schema_migrations': CREATE UNIQUE INDEX `unique_schema_migrations` ON `schema_migrations` (`version`)

あれ、インデックス作成に失敗している。
createでは付与されないのかー。改めて「INDEX」権限を付与します。
あと、migrateのスクリプトで、alter table文でカラムを追加、drop文でテーブルの削除をしているようなので、alter文、drop文も実行できるようにしました。

mysql> grant index,drop alter on redmine.* to redmine@localhost;
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

あらためてスクリプトを実行します。

# rake db:migrate RAILS_ENV="production"
(in /www/labs/redmine-0.8.5)

実行するとつらつらと実行結果が表示され、エラーがなければOKです。
次に、初期データをロードするスクリプトを流します。

# rake load_default_data RAILS_ENV="production"
(in /www/labs/redmine-0.8.5)
 
Select language: bg, ca, cs, da, de, en, es, fi, fr, he, hu, it, ja, ko, lt, nl, no, pl, pt, pt-br, ro, ru, sk, sr, sv, th, tr, uk, vn, zh, zh-tw [en] ja

ここで言語を選択しろと言われるので、「ja」を指定して実行します。

====================================
Default configuration data loaded.

Note: The rake task load_default_data has been deprecated, please use the replacement version redmine:load_default_data

最後になんだか警告が出ているのですが、これはスクリプト名を「redmine:load_default_data」とすればよさそう。

# rake redmine:load_default_data RAILS_ENV="production"

これでやってみたのですが、ブラウザからアクセスしてみるとInternal Server Errorが出ており、ログを見たところ、/tmp/sessions/以下にファイルが書き込めないエラーのようでした。
これはhttp://redmine.jp/tech_note/apache-passenger/のトラブルシューティング-パーミッションの問題にあるように、config/environment.rbのオーナーがrootになっていたためのようです。
所有者を変更して再起動したらうまくいきました。以下のような画面になります。
redmine-installed


phpMyAdmin

ずっとインストール話ばかりです。

LAMP環境でデータベースを使用する場合、phpMyAdminというツールを使ってDBを操作できるようにすると便利です。
CentOSの場合だと、yumで簡単にインストール出来ます。

# yum install phpMyAdmin
# service httpd restart

この設定は、/etc/httpd/conf.d/phpmyadmin.confに設定されます。
Aliasを設定してあるので、そこは把握しておく必要があるでしょう。
また、デフォルトでは以下の設定のなので、ローカル以外からアクセスする場合には変更する必要があります。

 
  Order Deny,Allow
  Deny from all
  Allow from 127.0.0.1


VistaにMySQLをインストール

MySQLのインストールの話。
壁が高すぎる。

まずは、PHP 5.3.0が出たその4でMySQLをインストールして、Vistaでサービス削除で設定の準備が出来たのでMySQL Server Instance Configuration Wizardで設定しました。
すると、以前×になっていたStart serviceのセクションは無事通過したものの、サービスの起動に失敗した、みたいなエラーが出た。
「サービス」を見てみるとすでにMySQLサービスは起動しているようなので、再度Wizardを起動してみるとStart serviceは通過したものの、以下のエラーメッセージが出た。(長い。コピー出来てよかった)

The security settings could not be applied to the database because the connection has failed with the following error.

Error Nr. 1045
Access denied for user ‘root’@'localhost’ (using password: YES)

If a personal firewall is running on your machine, please make sure you have opened the TCP port 3306 for connections. Otherwise no client application can connect to the server. After you have opened the port please press [Retry] to apply the security settings.

If you are re-installing after you just uninstalled the MySQL server please note that the data directory was not removed automatically. Therefore the old password from your last installation is still needed to connect to the server. In this case please select skip now and re-run the Configuration Wizard from the start menu.

一応Firewallを確認してみたら、開いていないっぽいし、XAMPPの設定が残っていたので一応削除して、プログラムを追加したり、TCP3306番を空けてみたり、Firewallをoffにしてretryしてみたのですが同じエラーが出ます。
しょうがないのでSkipして設定終了させます。

以前LinuxにMySQLを入れたときに、root@localhostの設定で色々苦労した覚えがあったのでそれかもと思ってやってみた。
確か、root@localhostと、root@xxxxでパスワードをlocalhostに設定しないといけなかったとかそんな問題だったと思ったけど・・・。

一応MySQLのrootパスワード設定でやっていることをやってみまたらどうも当たりくさい。

MySQL Command Line Clientを起動するとパスワードを聞かれるので、まだ設定されてない今はパスワードなしでログイン出来る(はず)。
その後、以下コマンドを発行します。(パスワードはpassにとりあえずしています)

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.1.36-community MySQL Community Server (GPL)
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> set password for root@localhost=password('pass');
Query OK, 0 rows affected (0.00 sec)
 
mysql>

そしてもう一度MySQL Command Line Clientを起動して先ほど設定したpassを入力するとログイン出来るはず。ログイン出来た。
とりあえず今日はここまで。