[rails] Mysql で Incorrect datetime value が発生

Rails 2.3.4 と Mysql 5.0 (Windows) の環境で、Unit Test を実行すると下記のエラーが発生。

>rake test:units
  1) Error:
test_should_authenticate_user(UserTest):
ActiveRecord::StatementInvalid: Mysql::Error: Incorrect datetime value: '2009-10-16 07:56:13 UTC' for column 'remember_token_expires_at' at row 1: INSERT INTO `users` (`salt`, `updated_at`, `crypted_password`, `remember_token_expires_at`, `id`, `remember_token`, `login`, `created_at`, `email`) VALUES ('356a192b7913b04c54574d18c28d46e6395428ab', '2009-10-15 07:56:13', '39e3509c8a1dff4e5b35850d970992321c4f1358', '2009-10-16 07:56:13 UTC', 1, '77de68daecd823babbb58edb1c8e14d7106e83bb', 'quentin', '2009-10-10 07:56:12', 'quentin@example.com')

Mysql の sql-mode を空白に設定することで解決しました。

my.ini
# Set the SQL mode to strict
#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sql-mode=''

参考:

Now, open the my.ini file located at c:program files/MySQL/MySQL
Server X.x/my.ini.
Add a # at the begining of the line: sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Type sql_mode='' on the next line and save the file.
restart mysql

fixed it

[Rails] Re: restful_authentication rspec failures "Mysql::Error: Incorre

ラベル: ,

MySQL 3.23.58 を CentOS 5.2 にインストールする

MySQL ::  世界でもっとも普及している、オープン ソース データベース

自社サーバを一台新調することになったのですが、とある事情から MySQL は Ver 3.23.58 を使用しなければならず、でも Apache は 2.2 系を使いたい!


というわけで、OS やその他の環境は最新の CentOS 5.2 を使用し、MySQL 3.23.58 はソースからインストールすることにしました。


しかしながら、最新の環境にきわめて古いソフトをインストールすると、ほぼ間違いなく躓くもので。



ダウンロード


まずはダウンロードですが、もはや公式サイトのアーカイブにも見当たりません・・・

ので、MySQL日本正規代理店の SoftAgency 様から拝借いたします。


$ wget http://download.softagency.net/MySQL/Downloads/MySQL-3.23/mysql-3.23.58.tar.gz
$ tar -zxvf mysql-3.23.58.tar.gz
$ cd mysql-3.23.58/


Configure


Makefile ファイルを作成するために、configure を実行します。


$ ./configure \
--prefix=/usr/local/mysql \
--with-charset=sjis \
--with-extra-charsets=all \
--with-mysqld-user=mysql \
--without-bench \
--localstatedir=/home/mysql/data

checking "LinuxThreads"... "Not found"
configure: error: This is a linux system and Linuxthreads was not
found. On linux Linuxthreads should be used. Please install Linuxthreads
(or a new glibc) and try again. See the Installation chapter in the
Reference Manual for more information.

やっぱりエラーが。

どうやら CentOS 5 では Linuxthreads はサポートされなくなったようで(CentOS 4 まではサポートされていたようです)、configure のオプションで thread の方法を指定します。


$ ./configure \
--prefix=/usr/local/mysql \
--with-charset=sjis \
--with-extra-charsets=all \
--with-mysqld-user=mysql \
--without-bench \
--localstatedir=/home/mysql/data \
--with-named-thread-libs="-lpthread"

checking for termcap functions library... configure: error: No curses/termcap library found

今度は、curses library がないとおっしゃいます。インストールし、再チャレンジ。


$ yum search ncurses
ncurses.i386 : A terminal handling library
ncurses-devel.i386 : Development files for the ncurses library

$ sudo yum install ncurses.i386
Package ncurses - 5.5-24.20060715.i386 is already installed.

$ sudo yum install ncurses-devel.i386
Installed: ncurses-devel.i386 0:5.5-24.20060715
Complete!

$ ./configure \
--prefix=/usr/local/mysql \
--with-charset=sjis \
--with-extra-charsets=all \
--with-mysqld-user=mysql \
--without-bench \
--localstatedir=/home/mysql/data \
--with-named-thread-libs="-lpthread"

MySQL has a Web site at http://www.mysql.com/ which carries details on the
latest release, upcoming features, and other information to make your
work or play with MySQL more productive. There you can also find
information about mailing lists for MySQL discussion.

Remember to check the platform specific part of the reference manual for
hints about installing MySQL on your platform. Also have a look at the
files in the Docs directory.

Thank you for choosing MySQL!


OK! うまくいきました!



Make


さて、お次はコンパイルです。


$ make
mysqld.o: In function `main':
mysqld.cc:(.text+0x3450): undefined reference to `my_fast_mutexattr'
mysqld.cc:(.text+0x3464): undefined reference to `my_fast_mutexattr'
mysqld.cc:(.text+0x3478): undefined reference to `my_fast_mutexattr'
mysqld.o:mysqld.cc:(.text+0x34a0): more undefined references to `my_fast_mutexattr' follow
collect2: ld returned 1 exit status
make[4]: *** [mysqld] エラー 1

my_fast_mutexattr が定義されてないと。

そこで、定義を強制するように修正します。


$ vi mysys/my_thr_init.c
/my_fast_mutexattr

#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t my_fast_mutexattr;
#endif

これを、下記のようにします。


//#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_t my_fast_mutexattr;
//#endif

これでなんとかコンパイルができました。



Maike Install


最後にインストールです。ここまでくればOKでしょう。


$ sudo make install

お疲れ様です!

ラベル: , ,

MySQLで行番号

MySQLで行番号を表示したいです。

データベースにMySQLを使っていて、INSERTするときにソート番号を得たいときなど、「SELECT時に行番号を表示したい」ということがたまにあります。


ずいぶん昔にそんなことがあって、その時は、一度Excelにコピペして、行番号をつけて、マクロでSQL文を生成、なんてことをやったのですが、MySQLではユーザ変数をつかうことで行番号を表示することが可能でした。


mysql> set @i=0;
mysql> select (@i:=@i+10) as position, name from users;
+----------+-------+
| position | name |
+----------+-------+
| 10 | hoge1 |
| 20 | hoge2 |
| 30 | hoge3 |
| 40 | hoge4 |
| 50 | hoge5 |
+----------+-------+

変数なんて初めて知りました(汗



ユーザによって定義された変数に値を保存し、後で参照することができます。これで1つのステートメントから次のステートメントに変数を移行させることができます。


MySQL :: MySQL 5.1 リファレンスマニュアル :: 8.4 ユーザによって定義された変数


ラベル: