前回の続き。
17.課題点の解決
――――――――――――――――――――――――――――――――――――――――
1.config/database.yml で利用している mysql のユーザーが root である。しかもパスワードなし。(ユーザー作って解決?)
2.development で動いている、production で動かさないとな。
昨日、上記2点の問題点があった。
解決しよう!おう!
18.config/database.yml で利用している mysql のユーザーが root である。しかもパスワードなし。
――――――――――――――――――――――――――――――――――――――――
これは、解決しないと・・・。
と言うか、そもそも、rootにパスワードがないのは、どうなんだ!
と言うことで、まずrootのパスワード保護からやろう。
とりあえず、mongrelを起動して現状をチェック。
SSHを利用してrootでログイン。
[root@localhost ~]# cd /srv/www/lighttpd/lr_portal/
[root@localhost lr_portal]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
これで、http://10.20.138.111:3000/ にアクセスしてみる。
うむ。ちゃんと動いている。
では、mysqlのrootユーザーにパスワードをつけよう。
「mysql root パスワード」でググって見る。
http://www.rfs.jp/server/mysql/02/01.html
↑ここに書いてあった。
[root@localhost ~]# mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> SET PASSWORD FOR root=PASSWORD('********');
ERROR 1133 (42000): Can't find any matching row in the user table
mysql>
注意:******** ←ここは、ちゃんと入力してますからね。
ぐはー。なんかエラーでた。
ERROR 1133 (42000): Can't find any matching row in the user table
なんか、user table がないみたい?
「ERROR 1133 (42000): Can't find any matching row in the user table」でググって見る。
http://kajuhome.com/cgi-bin/patio/patio.cgi?mode=view&no=273
↑このページ。ようするに、利用するDBを選択してないからだと書いてある。
やってみる。
mysql> use mysql;
Database changed
mysql> SET PASSWORD FOR root=PASSWORD('********');
ERROR 1133 (42000): Can't find any matching row in the user table
mysql>
注意:******** ←ここは、ちゃんと入力してますからね。
ぐはあぁぁー。だめぢゃん。
あ、同じページに
>パスワードの設定は、ユーザの後にホスト名を追加しなければならないようです。
>以下の様に、「ユーザ@ホスト」の様に指定してください。
>mysql> SET PASSWORD FOR root@localhost=PASSWORD('abcde');
なるほど。やってみよう。
mysql> use mysql;
Database changed
mysql> SET PASSWORD FOR root@localhost=PASSWORD('*******');
Query OK, 0 rows affected (0.00 sec)
注意:******** ←ここは、ちゃんと入力してますからね。
やった!成功!!!
これで、http://10.20.138.111:3000/ にアクセスして、
色々いじってみる。エラーが出るはず。
あれ?
めちゃめちゃ登録できるし・・・。
mongrelを再起動してみる。
[root@localhost lr_portal]# mongrel_rails stop
[root@localhost lr_portal]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
これで、http://10.20.138.111:3000/ にアクセスしてみる。
ビンゴ!
#28000Access denied for user 'root'@'localhost' (using password: NO)
パスワードがないって言うエラーが出た。
では、rails側でパスワードを設定してみる。
config/database.yml に設定したパスワードを設定して、アップロード。
あれ?同じ画面だ・・・。
mongrelを再起動してみる。
Mysql::Error: Lost connection to MySQL server during query: SHOW FIELDS FROM company_directories
ぬおおおぉ。
なんか、違うエラーが出た!!!
なんか、コネクションエラーっぽ・・・。
このエラー昨日もでなかったけ・・・?
このエラーはrailsからmysqlに接続するさいの認証のエラーだったはず・・・。
あ、
grant all privileges on *.* to fukushige@localhost identified by 'fuku' with grant option;
↑これやんなきゃだめなのか?
やってみよう。
[root@localhost lr_portal]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 58 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant all privileges on *.* to root@localhost identified by '*********' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql>
ついでに、mongrel再起動。
[root@localhost lr_portal]# mongrel_rails stop
[root@localhost lr_portal]# mongrel_rails start
これで、アクセスしてみる。
Mysql::Error: Lost connection to MySQL server during query: SHOW FIELDS FROM company_directories
むあぁ。おなじだ!!!
mysql を再起動してみよう。
その後、mongrelも再起動。
[root@localhost lr_portal]# /etc/init.d/mysqld restart
MySQL を停止中: [ OK ]
MySQL を起動中: [ OK ]
[root@localhost lr_portal]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
で、アクセスしてみる。
Mysql::Error: Lost connection to MySQL server during query: SHOW FIELDS FROM company_directories
ぐはー。変わらん・・・。
DBへのアクセスエラーだな・・・。
もちつけ、もちつくんだ・・・。
[root@localhost lr_portal]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16 to server version: 5.0.22
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> grant all privileges on lr_portal_production.* to root@localhost identified by '**********' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on lr_portal_test.* to root@localhost identified by '**********' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on lr_portal_development.* to root@localhost identified by '**********' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql>
上記のように権限を設定してみる。
mysql再起動。
mongrel再起動。
[root@localhost lr_portal]# /etc/init.d/mysqld restart
MySQL を停止中: [ OK ]
MySQL を起動中: [ OK ]
[root@localhost lr_portal]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
で、アクセスしてみる。
Mysql::Error: Lost connection to MySQL server during query:
むむーん。変わらん・・・。何なの??
rootだからダメなのかな?
他のユーザを設定してみてやってみるか。
昨日
grant all privileges on lr_portal_production.* to fukushige@localhost identified by '****' with grant option;
grant all privileges on lr_portal_development.* to fukushige@localhost identified by '****' with grant option;
grant all privileges on lr_portal_test.* to fukushige@localhost identified by '****' with grant option;
とやっていたので、
database.yml の内容を
username: fukushige
password: fuku
にしてみる。
アップ、mysql,mongrel 再起動。
で、見てみる。
Mysql::Error: Lost connection to MySQL server during query:
ぐはぁぁあぁー!変わらん。
関係ないか・・・?
もっと、基本に返ろう。
railsの入門書を見てみよう。
config/database.yml で文字コードを指定していなかったので、指定してみる。
encoding: utf8
ついでに、config/environment.rb の一番上に $KCODE = "UTF8" を加えてみる。
次に、本に、rails と言うユーザーを作成しますと書いてあるが・・・これは必須??
とりあえず、作ってみる。
mysql> grant usage on *.* to rails@localhost identified by 'rails_rails';
Query OK, 0 rows affected (0.00 sec)
[root@localhost lr_portal]# /etc/init.d/mysqld restart
MySQL を停止中: [ OK ]
MySQL を起動中: [ OK ]
[root@localhost lr_portal]# mongrel_rails start
む、なんかエラーが変わった。
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
「SET NAMES 'utf8'」でググって見る。
http://phpspot.net/php/pgMySQL4.1%8CnUTF-8%82%CC%8F%EA%8D%87.html
↑に
>MySQL4.1系ではデフォルトでUTF-8文字列が使われます。
>PHPから普通にデータ挿入をしようとすると、文字化けします。
>SQL文を発行するまえに、クライアントの文字コード設定をしましょう。
>文字コードの設定は次の構文で行います。
>UTF8に設定するには次のSQL文を実行します。
>mysql> SET NAMES utf8;
とりあえず、やってみるか。
mysql> SET NAMES utf8;
Query OK, 0 rows affected (0.00 sec)
で、mysql,mongrel再起動。
[root@localhost lr_portal]# /etc/init.d/mysqld restart
MySQL を停止中: [ OK ]
MySQL を起動中: [ OK ]
[root@localhost lr_portal]# mongrel_rails start
で、見てみる。
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
変わらん・・。なんだろう・・・。
もう一度、
「Mysql Error Lost connection to MySQL server during query: SET NAMES utf8」でググって見る。
http://itpro.nikkeibp.co.jp/article/COLUMN/20060424/236113/?ST=lin-server&P=3
↑このページだと、
GRANT ALL PRIVILEGES ON addressbook.* TO ab@localhost IDENTIFIED BY 'ab';
やってるので、応用でやってみる。
GRANT ALL PRIVILEGES ON lr_portal_development.* TO rails@localhost IDENTIFIED BY 'rails_rails';
GRANT ALL PRIVILEGES ON lr_portal_test.* TO rails@localhost IDENTIFIED BY 'rails_rails';
GRANT ALL PRIVILEGES ON lr_portal_production.* TO rails@localhost IDENTIFIED BY 'rails_rails';
で、mysql,mongrel再起動。
※config/database.yml は
adapter: mysql
database: lr_portal_development
username: rails
password: rails_rails
encoding: utf8
host: localhost
socket: /var/lib/mysql/mysql.sock
↑な感じです。
[root@localhost lr_portal]# /etc/init.d/mysqld restart
MySQL を停止中: [ OK ]
MySQL を起動中: [ OK ]
[root@localhost lr_portal]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
で、見てみる。
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
変わらん・・・。むごー。
http://blogs.dion.ne.jp/koko/archives/4345309.html#more
mysqlの設定ファイルを発見。
/etc/my.cnf
http://d.hatena.ne.jp/shingotada/searchdiary?word=*[linux]
↑のページに、
>rubyのヘッダーをインストールしていない
と書いてある・・・。
rubyのヘッダー?
yum install ruby-devel
[root@localhost lr_portal]# yum install ruby-devel
Loading "installonlyn" plugin
Loading "fastestmirror" plugin
Loading "priorities" plugin
Setting up Install Process
Setting up repositories
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
0 packages excluded due to repository priority protections
Parsing package install arguments
Nothing to do
うまくいかない・・・。パッケージがない??
「ruby-devel Nothing to do」でググって見る。
・・・よくわからん・・・。
http://l5web.laser5.co.jp/rpm2html/7.2exp/ruby-devel-1.6.4-2.i386.html
↑このページにrpmがあったので、ダウンロード、インストールしてみる。
[root@localhost opt]# rpm -i ruby-devel-1.6.4-2.i386.rpm
エラー: 依存性の欠如:
ruby = 1.6.4-2 は ruby-devel-1.6.4-2.i386 に必要とされています
はぁ・・・。依存性の欠如?
わけわからんので、違う方法を検討する。
最初に戻ろう。
現状把握。
[root@localhost lr_portal]# mongrel_rails start
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.
mongrelスタートさせて、http://10.20.138.111:3000/ を見ると。
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
こうなる。
エラーメッセージは、接続がおかしいと言っている。
SET NAMES 'utf8' がなぞだ。
文字コードはutf8でDBもrailsも作っているのに・・・。
config/database.yml も config/environment.rb もutf8の設定にしてある。
うーん。
おもむろに、
「SET NAMES utf8 mysql rails」
とググって見る。
http://wota.jp/ac/?date=20061011
↑このページを見つける。
mysql> status
--------------
mysql Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu (i686) using readline 5.0
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.0.22
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 2 hours 53 min 25 sec
Threads: 1 Questions: 4 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 6 Queries per second avg: 0.000
--------------
mysql> show variables like "char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
mysql> set names utf8;
Query OK, 0 rows affected (0.00 sec)
↑これをやると。
mysql> status
--------------
mysql Ver 14.12 Distrib 5.0.22, for redhat-linux-gnu (i686) using readline 5.0
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.0.22
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/lib/mysql/mysql.sock
Uptime: 2 hours 54 min 51 sec
Threads: 1 Questions: 10 Slow queries: 0 Opens: 0 Flush tables: 1 Open tables: 6 Queries per second avg: 0.001
--------------
mysql> show variables like "char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
utf8の部分が増える。
>/etc/my.cnf の設定
>MySQL は空気(実行時のオプション)が読めないようなので、設定ファイルではっきりと明示しておくしかなさそうだ。
なるほど。明示的にしておこう。
[root@localhost etc]# emacs /etc/my.cnf
↑で
default-character-set=utf8
skip-character-set-client-handshakedatadir=/var/lib/mysql
を追加した。
[mysqld]
default-character-set=utf8
skip-character-set-client-handshakedatadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
[mysql.server]
user=mysql
basedir=/var/lib
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
これで、Mysqlとmongrelを再起動してみる。
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
うーむ、あかん・・・・おなじだ・・・・。
ふと思い立ち、
config/database.yml の文字コードを Shift_JIS から utf-8 にしてみる。
・・・アスキーコードしか使ってないし・・関係ないと思うけど・・・・。
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
うーん。見事に玉砕・・・。関係なかった・・・。
DBから作り直してみるか・・・。
mysql> drop database lr_portal_development;
Query OK, 14 rows affected (0.03 sec)
mysql> drop database lr_portal_test;
Query OK, 0 rows affected (0.00 sec)
mysql> drop database lr_portal_production;
Query OK, 1 row affected (0.00 sec)
↑DB削除。
ああー、今思うと、これって、文字化けとかの問題で、接続できないとかは、別問題か・・・。
まぁとりあえず、作ろう・・・。
mysql> create database lr_portal_development default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> create database lr_portal_test default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> create database lr_portal_production default character set utf8;
Query OK, 1 row affected (0.00 sec)
DB作成完了!
つぎに、migrate
[root@localhost lr_portal]# rake migrate
(in /srv/www/lighttpd/lr_portal)
rake aborted!
Mysql::Error: Lost connection to MySQL server during query: SET NAMES 'utf8'
(See full trace by running task with --trace)
はぁ...。これっすよ...。
先ほどの、mysqlの設定で、rails側でutf8の宣言はいらなくなったはずなので、
おもむろに、
config/database.yml の
encoding: utf8
を削除して rake migrate してみる。
[root@localhost lr_portal]# rake migrate
(in /srv/www/lighttpd/lr_portal)
rake aborted!
Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info
(See full trace by running task with --trace)
あ!!!反応変わった!!!
config/database.yml の記法ミス??だったのか??
しかも、このエラーは昨日見たような・・・。
mysql> use lr_portal_development
Database changed
mysql> CREATE TABLE schema_info
-> (
-> version INT NOT NULL
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
昨日と同じようにう作ってみる。
mysql> insert into schema_info set version=0;
Query OK, 1 row affected (0.01 sec)
これで、 rake db:migrate
[root@localhost lr_portal]# rake db:migrate
(in /srv/www/lighttpd/lr_portal)
rake aborted!
Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info
(See full trace by running task with --trace)
あれーーー??
あ、権限設定してない・・・。
mysql> grant all privileges on lr_portal_production.* to rails@localhost identified by 'rails_rails' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on lr_portal_development.* to rails@localhost identified by 'rails_rails' with grant option
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on lr_portal_test.* to rails@localhost identified by 'rails_rails' with grant option;
Query OK, 0 rows affected (0.00 sec)
これで、やってみる。
[root@localhost lr_portal]# rake db:migrate
(in /srv/www/lighttpd/lr_portal)
rake aborted!
Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info
(See full trace by running task with --trace)
ぐはーーー。
なんなんだろう・・・・。
http://d.hatena.ne.jp/niraikanaibird/searchdiary?word=*[mysql]
http://rails.office.drecom.jp/q1w2e3r4/daily/200606/30
↑これによると、
yum install mysql-devel
↑これして、
gem install mysql -- --with-mysql-config=`which mysql_config`
↑これするらしいが、
yum install mysql-devel
↑これが失敗する。
[root@localhost /]# yum install mysql-devel
Loading "installonlyn" plugin
Loading "fastestmirror" plugin
Loading "priorities" plugin
Setting up Install Process
Setting up repositories
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
0 packages excluded due to repository priority protections
Parsing package install arguments
Nothing to do
これを成功させよう・・・。
その前に・・・。
インストールされているパッケージを確認。
http://www.linux.or.jp/JF/contrib/LILO-doc/rpm-3.html
[root@localhost /]# rpm -qa | grep mysql
mysql-5.0.22-2.1
mysql-bench-5.0.22-2.1
libdbi-dbd-mysql-0.8.1a-1.2.2
mod_auth_mysql-3.0.0-3.1
mysql-connector-odbc-3.51.12-2.2
mysql-devel-5.0.22-2.1
mysql-server-5.0.22-2.1
php-mysql-5.1.6-11.el5
入ってるし!!!
mysql-devel-5.0.22-2.1
ぢゃあ、
gem install mysql -- --with-mysql-config=`which mysql_config`
こっちの問題か・・・。
http://d.hatena.ne.jp/catalina/searchdiary?word=*[shopping%20cart]
↑このページには、
gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
と書いてあるので、やってみる。
[root@localhost /]# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config
Attempting local installation of 'mysql'
Local gem file not found: mysql*.gem
Attempting remote installation of 'mysql'
Select which gem to install for your platform (i386-linux)
1. mysql 2.7.3 (mswin32)
2. mysql 2.7.1 (mswin32)
3. mysql 2.7 (ruby)
4. mysql 2.6 (ruby)
5. mysql 2.5.1 (ruby)
6. Cancel installation
> 3
Building native extensions. This could take a while...
mysql.c: In function ‘make_field_obj’:
mysql.c:185: 警告: unused variable ‘hash’
mysql.c: In function ‘stmt_execute’:
mysql.c:1316: 警告: unused variable ‘false’
mysql.c: In function ‘time_initialize’:
mysql.c:1703: 警告: control reaches end of non-void function
mysql.c: In function ‘stmt_execute’:
mysql.c:1365: 警告: ‘t.time_type’ is used uninitialized in this function
mysql.c:1378: 警告: ‘t.time_type’ is used uninitialized in this function
ruby extconf.rb install mysql -- --with-mysql-config=/usr/bin/mysql_config
checking for mysql_ssl_set()... yes
checking for mysql.h... yes
creating Makefile
make
gcc -I. -I. -I/usr/lib/ruby/1.8/i386-linux -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Wall -fPIC -c mysql.c
gcc -shared -L"/usr/lib" -o mysql.so mysql.o -lruby -L/usr/lib/mysql -lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib -lssl -lcrypto -lpthread -ldl -lcrypt -lm -lc
make install
/usr/bin/install -c -m 0755 mysql.so /usr/lib/ruby/gems/1.8/gems/mysql-2.7/lib
Successfully installed mysql-2.7
[root@localhost /]#
これって成功なの???
もちつけ、もちつくんだ。
昨日は、rootパスワード設定前で、ちゃんとアクセスできたんだ。
rootのパスワードを設定した瞬間から、はじかれるようになった。
ということで、パスワードをセットする前にしてみよう。
mysql> use mysql
mysql> SET PASSWORD FOR root@localhost=PASSWORD('');
これで、root のパスワードをなしにする。
そして、rake migrate
[root@localhost lr_portal]# rake migrate
(in /srv/www/lighttpd/lr_portal)
== CreateUnits: migrating =====================================================
-- create_table(:units)
-> 0.0081s
== CreateUnits: migrated (0.0087s) ============================================
== CreatePositions: migrating =================================================
-- create_table(:positions)
-> 0.0044s
== CreatePositions: migrated (0.0050s) ========================================
== CreateWorkForms: migrating =================================================
-- create_table(:work_forms)
-> 0.0162s
== CreateWorkForms: migrated (0.0167s) ========================================
== CreateUserAuthorizations: migrating ========================================
-- create_table(:user_authorizations)
-> 0.0043s
== CreateUserAuthorizations: migrated (0.0049s) ===============================
== CreateCompanyDirectories: migrating ========================================
-- create_table(:company_directories)
-> 0.0085s
== CreateCompanyDirectories: migrated (0.0091s) ===============================
== CreateUsers: migrating =====================================================
-- create_table(:Users)
-> 0.0047s
== CreateUsers: migrated (0.0053s) ============================================
== CreateChangeLogs: migrating ================================================
-- create_table(:change_logs)
-> 0.0065s
== CreateChangeLogs: migrated (0.0071s) =======================================
== CreateAuthentications: migrating ===========================================
-- create_table(:authentications)
-> 0.0047s
== CreateAuthentications: migrated (0.0054s) ==================================
== CreateAuthResponses: migrating =============================================
-- create_table(:auth_responses)
-> 0.0051s
== CreateAuthResponses: migrated (0.0057s) ====================================
== CreateReports: migrating ===================================================
-- create_table(:reports)
-> 0.0052s
== CreateReports: migrated (0.0059s) ==========================================
== CreateComments: migrating ==================================================
-- create_table(:comments)
-> 0.0053s
== CreateComments: migrated (0.0058s) =========================================
== CreateReportTypes: migrating ===============================================
-- create_table(:report_types)
-> 0.0043s
== CreateReportTypes: migrated (0.0049s) ======================================
== CreateReportsAuthentications: migrating ====================================
-- create_table(:reports_authentications)
-> 0.0046s
== CreateReportsAuthentications: migrated (0.0052s) ===========================
おおおおぉぉぉ。うまくいく・・・。
なんでパスワード設定するとだめなの・・・?
とりあえず、root のままでは、マズいので、他のユーザーを設定する。
ユーザーを rails にしてやってみよう。
とりあえず、
[root@localhost lr_portal]# rake migrate VERSION=0
(in /srv/www/lighttpd/lr_portal)
== CreateReportsAuthentications: reverting ====================================
-- drop_table(:reports_authentications)
-> 0.0067s
== CreateReportsAuthentications: reverted (0.0072s) ===========================
== CreateReportTypes: reverting ===============================================
-- drop_table(:report_types)
-> 0.0027s
== CreateReportTypes: reverted (0.0033s) ======================================
== CreateComments: reverting ==================================================
-- drop_table(:comments)
-> 0.0024s
== CreateComments: reverted (0.0029s) =========================================
== CreateReports: reverting ===================================================
-- drop_table(:reports)
-> 0.0023s
== CreateReports: reverted (0.0030s) ==========================================
== CreateAuthResponses: reverting =============================================
-- drop_table(:auth_responses)
-> 0.0024s
== CreateAuthResponses: reverted (0.0030s) ====================================
== CreateAuthentications: reverting ===========================================
-- drop_table(:authentications)
-> 0.0027s
== CreateAuthentications: reverted (0.0032s) ==================================
== CreateChangeLogs: reverting ================================================
-- drop_table(:change_logs)
-> 0.0024s
== CreateChangeLogs: reverted (0.0029s) =======================================
== CreateUsers: reverting =====================================================
-- drop_table(:users)
rake aborted!
Mysql::Error: #42S02Unknown table 'users': DROP TABLE users
(See full trace by running task with --trace)
で、DBを戻す。
それで、mysql のユーザー作成。
mysql> grant all privileges on lr_portal_development.* to rails@localhost identified by '' with grant option;
で、パスワードなしで作ってみる。
config/database.yml の接続 username を rails にしてやってみる。
[root@localhost lr_portal]# rake migrate
(in /srv/www/lighttpd/lr_portal)
== CreateChangeLogs: migrating ================================================
-- create_table(:change_logs)
-> 0.0102s
== CreateChangeLogs: migrated (0.0108s) =======================================
== CreateAuthentications: migrating ===========================================
-- create_table(:authentications)
-> 0.0052s
== CreateAuthentications: migrated (0.0058s) ==================================
== CreateAuthResponses: migrating =============================================
-- create_table(:auth_responses)
-> 0.0049s
== CreateAuthResponses: migrated (0.0054s) ====================================
== CreateReports: migrating ===================================================
-- create_table(:reports)
-> 0.0055s
== CreateReports: migrated (0.0061s) ==========================================
== CreateComments: migrating ==================================================
-- create_table(:comments)
-> 0.0176s
== CreateComments: migrated (0.0182s) =========================================
== CreateReportTypes: migrating ===============================================
-- create_table(:report_types)
-> 0.0222s
== CreateReportTypes: migrated (0.0227s) ======================================
== CreateReportsAuthentications: migrating ====================================
-- create_table(:reports_authentications)
-> 0.0043s
== CreateReportsAuthentications: migrated (0.0049s) ===========================
[root@localhost lr_portal]#
おおおおおおぉ。ユーザー名 rails でいけた!!!
なんでパスワード設定するとだめなの????
ということで、root はパスワード設定する。
mysql> SET PASSWORD FOR root@localhost=PASSWORD('******');
Query OK, 0 rows affected (0.00 sec)
これで、rake migrate ができなくなったってことないよな・・・。
[root@localhost lr_portal]# rake migrate VERSION=0
(in /srv/www/lighttpd/lr_portal)
== CreateReportsAuthentications: reverting ====================================
-- drop_table(:reports_authentications)
-> 0.0080s
== CreateReportsAuthentications: reverted (0.0085s) ===========================
== CreateReportTypes: reverting ===============================================
-- drop_table(:report_types)
-> 0.0028s
== CreateReportTypes: reverted (0.0034s) ======================================
== CreateComments: reverting ==================================================
-- drop_table(:comments)
-> 0.0024s
== CreateComments: reverted (0.0029s) =========================================
== CreateReports: reverting ===================================================
-- drop_table(:reports)
-> 0.0027s
== CreateReports: reverted (0.0033s) ==========================================
== CreateAuthResponses: reverting =============================================
-- drop_table(:auth_responses)
-> 0.0027s
== CreateAuthResponses: reverted (0.0033s) ====================================
== CreateAuthentications: reverting ===========================================
-- drop_table(:authentications)
-> 0.0026s
== CreateAuthentications: reverted (0.0032s) ==================================
== CreateChangeLogs: reverting ================================================
-- drop_table(:change_logs)
-> 0.0025s
== CreateChangeLogs: reverted (0.0030s) =======================================
== CreateUsers: reverting =====================================================
-- drop_table(:users)
rake aborted!
Mysql::Error: #42S02Unknown table 'users': DROP TABLE users
(See full trace by running task with --trace)
[root@localhost lr_portal]# rake migrate
(in /srv/www/lighttpd/lr_portal)
== CreateChangeLogs: migrating ================================================
-- create_table(:change_logs)
-> 0.0107s
== CreateChangeLogs: migrated (0.0112s) =======================================
== CreateAuthentications: migrating ===========================================
-- create_table(:authentications)
-> 0.0054s
== CreateAuthentications: migrated (0.0060s) ==================================
== CreateAuthResponses: migrating =============================================
-- create_table(:auth_responses)
-> 0.0052s
== CreateAuthResponses: migrated (0.0057s) ====================================
== CreateReports: migrating ===================================================
-- create_table(:reports)
-> 0.0054s
== CreateReports: migrated (0.0060s) ==========================================
== CreateComments: migrating ==================================================
-- create_table(:comments)
-> 0.0058s
== CreateComments: migrated (0.0064s) =========================================
== CreateReportTypes: migrating ===============================================
-- create_table(:report_types)
-> 0.0043s
== CreateReportTypes: migrated (0.0049s) ======================================
== CreateReportsAuthentications: migrating ====================================
-- create_table(:reports_authentications)
-> 0.0047s
== CreateReportsAuthentications: migrated (0.0053s) ===========================
[root@localhost lr_portal]#
む大丈夫だ!!
うごく!!
とりあえず、これでよい。
パスワード設定は、違うタスクでやろう・・・。
19.development で動いている、production で動かさないとな。
――――――――――――――――――――――――――――――――――――――――
はぁ・・・長かった・・・。
とりあえず、ユーザー名 rails パスワードなし。で動かすとして、
(パスワード設定は違うタスクでやる。)
で、次!!
今は、DBが development で動いている。
それを、production で動かそうと言うことをやる。
「mongrel production」でググって見る。
http://d.hatena.ne.jp/pushiganga/20070422
↑には
>rake db:migrate RAILS_ENV=production
と書いてある。migrateでは、↑やるのか?
mongrel はどうやるんだ??
なんか、前見たな・・・・。
http://www.fkino.net/hiki/?MongrelInstall
↑には、
mongrel_rails start -p 10080 -d -e production
と書いてある。
やってみよう。
[root@localhost lr_portal]# rake db:migrate RAILS_ENV=production
(in /srv/www/lighttpd/lr_portal)
rake aborted!
#28000Access denied for user 'rails'@'localhost' (using password: YES)
(See full trace by running task with --trace)
ぐはー。
あああ、権限設定か・・・。
mysql> grant all privileges on lr_portal_test.* to rails@localhost identified by '' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on lr_portal_production.* to rails@localhost identified by '' with grant option;
Query OK, 0 rows affected (0.00 sec)
これでやってみよう。
[root@localhost lr_portal]# rake db:migrate RAILS_ENV=production
(in /srv/www/lighttpd/lr_portal)
rake aborted!
#28000Access denied for user 'rails'@'localhost' (using password: YES)
(See full trace by running task with --trace)
[root@localhost lr_portal]#
ぐはーーーー。なんで?
あ!!
config/database.yml の更新忘れてた・・・。
更新、アップ、それで再度やってみる。
[root@localhost lr_portal]# rake db:migrate RAILS_ENV=production
(in /srv/www/lighttpd/lr_portal)
== CreateUnits: migrating =====================================================
-- create_table(:units)
-> 0.0057s
== CreateUnits: migrated (0.0063s) ============================================
== CreatePositions: migrating =================================================
-- create_table(:positions)
-> 0.0043s
== CreatePositions: migrated (0.0049s) ========================================
== CreateWorkForms: migrating =================================================
-- create_table(:work_forms)
-> 0.0041s
== CreateWorkForms: migrated (0.0047s) ========================================
== CreateUserAuthorizations: migrating ========================================
-- create_table(:user_authorizations)
-> 0.0282s
== CreateUserAuthorizations: migrated (0.0288s) ===============================
== CreateCompanyDirectories: migrating ========================================
-- create_table(:company_directories)
-> 0.0118s
== CreateCompanyDirectories: migrated (0.0124s) ===============================
== CreateUsers: migrating =====================================================
-- create_table(:Users)
-> 0.0048s
== CreateUsers: migrated (0.0053s) ============================================
== CreateChangeLogs: migrating ================================================
-- create_table(:change_logs)
-> 0.0050s
== CreateChangeLogs: migrated (0.0055s) =======================================
== CreateAuthentications: migrating ===========================================
-- create_table(:authentications)
-> 0.0049s
== CreateAuthentications: migrated (0.0056s) ==================================
== CreateAuthResponses: migrating =============================================
-- create_table(:auth_responses)
-> 0.0050s
== CreateAuthResponses: migrated (0.0055s) ====================================
== CreateReports: migrating ===================================================
-- create_table(:reports)
-> 0.0229s
== CreateReports: migrated (0.0234s) ==========================================
== CreateComments: migrating ==================================================
-- create_table(:comments)
-> 0.0049s
== CreateComments: migrated (0.0055s) =========================================
== CreateReportTypes: migrating ===============================================
-- create_table(:report_types)
-> 0.0070s
== CreateReportTypes: migrated (0.0075s) ======================================
== CreateReportsAuthentications: migrating ====================================
-- create_table(:reports_authentications)
-> 0.0042s
== CreateReportsAuthentications: migrated (0.0047s) ===========================
[root@localhost lr_portal]#
おおおおぉ。成功!!!
ちゃんと確認してみる。
mysql> use lr_portal_production
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_lr_portal_production |
+--------------------------------+
| Users |
| auth_responses |
| authentications |
| change_logs |
| comments |
| company_directories |
| positions |
| report_types |
| reports |
| reports_authentications |
| schema_info |
| units |
| user_authorizations |
| work_forms |
+--------------------------------+
14 rows in set (0.00 sec)
うむ。ちゃんとできてる。
あとは、mongrel!!
さっきの調べで、
mongrel_rails start -p 10080 -d -e production
とやると production のDB を見ると書いてあった。
というか、ポートは 3000 でよいので、
mongrel_rails start -p 3000 -d -e production
となるのか?
とりあえず、やってみる。
[root@localhost lr_portal]# mongrel_rails start -p 3000 -d -e production
[root@localhost lr_portal]#
なんか、シンプルな反応だな・・・。オプションの影響か...。
でアクセスしてみる。
http://10.20.138.111:3000/
おお見れる!!!
色々更新してみる。
おおおおおおぉ、色々更新可能!!!DBと連携している!!
では、mysql の lr_portal_production の中身を見てみましょう。
mysql> use lr_portal_production
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_lr_portal_production |
+--------------------------------+
| Users |
| auth_responses |
| authentications |
| change_logs |
| comments |
| company_directories |
| positions |
| report_types |
| reports |
| reports_authentications |
| schema_info |
| units |
| user_authorizations |
| work_forms |
+--------------------------------+
14 rows in set (0.00 sec)
mysql> select * from positions;
+----+-----------------------+
| id | position_name |
+----+-----------------------+
| 1 | 代表取締役社長 |
+----+-----------------------+
1 row in set (0.00 sec)
mysql>
おおおおおおおぉお。
lr_portal_production が更新されてる!!!
だいじょうぶだ!!
とりあえず、これで完了。
20.課題点
――――――――――――――――――――――――――――――――――――――――
1.railsに設定するユーザーにパスワードを付けると、アクセスできなくなるので、
パスワードつきでアクセスできるようにする。あとでやろう。