2014年7月11日金曜日

MySQLでテーブル作成でエラーが出た時の詳細ログチェックの方法

MySQLで例えばテーブルを作成する時に外部キー制約などが間違ってた場合、error no 150と言われてもさっぱり分からないので、以下のコマンドで詳細をチェック。

>SHOW ENGINE INNODB STATUS

外部キーであれば、テーブル名が存在しないなどと詳しいエラーを教えてくれる。

http://stackoverflow.com/questions/17812616/mysql-error-1005-cant-create-table-errno-150

2014年7月10日木曜日

ELF header smaller than expectedがUbuntuのアップデート後の再起動で出た場合

ELF header smaller than expectedがUbuntuのアップデート後の再起動で出た場合、以下の手順で治します。


  1. UbuntuのブータブルUSBスティックを作る
  2. USBスティックからブート
  3. boot-repairをインストール
    • sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
  4. boot-repairを実行
    • sudo apt-get install -y boot-repair && (boot-repair &)
  5. リブートしてOK


http://askubuntu.com/questions/401105/elf-header-smaller-than-expected

2014年6月27日金曜日

mysqlでダンプファイルから特定の列をリストアするには?

idを指定してやる場合。

mysqldump -uroot -p db_name table_name --where='id<1000000'

http://stackoverflow.com/questions/5658284/how-to-use-mysqldump-for-a-portion-of-a-table

MySQLでカラムの値を分割して抽出するには?

MySQLでカラムの値を分割して抽出するには、SUBSTRING_INDEX関数を使ってやる。

mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', 2); -> 'www.mysql' mysql> SELECT SUBSTRING_INDEX('www.mysql.com', '.', -2); -> 'mysql.com'

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substring-index

3つめの数値の引数がポイント。正の数は左から数えて、負の数は右から数えて、いくつめの分割された値かを指す。

MySQLでのフロー制御関数の扱い方

MySQLでIF-ELSE IF-ELSE的な事をしたい場合、こうする。

mysql> SELECT CASE 1 WHEN 1 THEN 'one'
    ->     WHEN 2 THEN 'two' ELSE 'more' END;
        -> 'one'
mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
        -> 'true'
mysql> SELECT CASE BINARY 'B'
    ->     WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
        -> NULL

http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html

2014年6月3日火曜日

SpringでJSONを返す場合に、特定のフィールドを表示させ無いようにするにはObjectMapperのaddMixInAnnotationsを使う。

SpringでJSONを返す場合に、特定のフィールドを表示させ無いようにするには、JacksonのObjectMapperで、addMixInAnnotationsに表示させたく無いフィールドを設定した抽象クラス、もしくはインターフェイスを大元のJSONオブジェクトにマップしたクラスに教えてやる。

Snippet

@Controller
public class SubjectController

{
    private ObjectMapper _objectMapper = new ObjectMapper();

    public Controller()
    {
    _objectMapper.getSerializationConfig().addMixInAnnotations(Base.class, FieldsNotAvailable.class);

    }

    @RequestMapping(value="/path", method={RequestMethod.GET})
    public @ResponseBody String getJson(ModelMap model)
    {
        return _objectMapper.writeValueAsString(subject);
    }
}

public abstract class FiledsNotAvailable
{
    @JsonIgnore
    public abstract String getSomeField();
}

http://stackoverflow.com/questions/22609079/how-to-filter-the-json-response-returning-from-spring-rest-web-service
http://fasterxml.github.io/jackson-databind/javadoc/2.0.0/com/fasterxml/jackson/databind/ObjectMapper.html#addMixInAnnotations(java.lang.Class, java.lang.Class)

2014年4月11日金曜日

Ubuntuでheartbleedで問題となっているOpenSSLのパッケージを確認する方法

OpenSSLのバージョンを確認するには

% openssl version -a 

OpenSSL 1.0.1e 11 Feb 2013
built on: Mon Apr  7 20:33:19 UTC 2014 ---------->ここの日付を確認する。4月7日以降であれば最新らしい。
platform: debian-amd64
options:  bn(64,64) rc4(16x,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: cc -fPIC -DOPENSSL_PIC -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -DTERMIO -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DOPENSSL_NO_TLS1_2_CLIENT -DOPENSSL_MAX_TLS1_2_CIPHER_LENGTH=50 -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
OPENSSLDIR: "/usr/lib/ssl"

http://askubuntu.com/questions/444848/why-unattended-upgrades-does-not-fix-heartbleed-bug


10.04 LTSは古いOpenSSLなので更新しなくても大丈夫なようです。
http://askubuntu.com/questions/445164/update-openssl-to-1-x-on-10-04-lts-to-avoid-heartbleed-vulnerability

Ubuntuのアップデートは、

% sudo apt-get upgrade
% sudo apt-get update

それでもアップデートされない場合は、
% sudo dist-upgrade ---->これは現在使ってるパッケージが削除される場合があるので注意。

https://blog.pay4bugs.com/2014/04/08/howto-update-ubuntu-to-fix-heartbleed-ssl-bug/
http://askubuntu.com/questions/215267/will-apt-get-dist-upgrade-upgrade-my-system-to-newer-version
https://wiki.ubuntu.com/Security/Upgrades