2013年6月6日木曜日

MySQLにログインできない時の対処



MySQLのセットアップを毎度忘れて毎度時間をかけてしまう。
前に入れて満足じまいだったので今回はメモする。
無論自分だけでは対処できなかった屑である

久々にSQL使う用事ができたため以下を実行。
>mysql5 -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

こんなエラーが出てきてMySQLに入れない現象に陥った。
パスワードを設定は行っていなかったはず。

いろいろ調べた結果、とりあえずSQLは止めた方がよいと
>sudo /opt/local/share/mysql5/mysql/mysql.server stop

次に、以下のコマンドを実行した
>sudo mysqld_safe5 --user=root --skip-grant-tables
バックグラウンドで動かしたいときは & を語尾にくわえる

>mysql5 -u root
これで一応入れるようになる。mysqld_safe5で実行したのを止めよう。

ROOTユーザを追加したいため、とりあえず
>flush pgesrivile;
を実行する。これをしないとお前じゃ無理と怒られる。

grant all privileges on *.* to root@localhost identified by 'PASSWORD' with grant option;
これで追加できます。

>mysql5 -u root -pPASSWORD

おしまい。
参考になりました。
http://www.goofoo.jp/2011/11/1457

また、上記エラーが出ても
>mysql5
で入ることができる。
でもなんか、やっぱりパスワードあった方がいいよね、いろいろと。

ちなみにmysqld_safe5はCtrl+cで殺せなかった・・・・
>ps aux | grep mysqld_safe
とすると、端末閉じたとしても残っています。
>sudo kill -9 プロセスナンバー
 で殺しましょう。
 なんでなのかな、にわかなのでわかりません。

2013年1月16日水曜日

RubyでCSVをXMLに変換

あまり汎用性はないですが・・・
勉強がてらに書いてみました。
 某ペンを管理するツールを作ろうかと最近思い、とりあえず色の基本データをXMLに書き出すことにしました。
builder/xmlmarkupを使うと随分直感的な表現でXMLが書けます。感動した。
ruby 1.9で書いてます。


# encoding: utf-8
require 'builder/xmlmarkup'
require 'csv'
xm = Builder::XmlMarkup.new :indent => 2
xm.instruct! directive_tag=:xml, :encoding=> 'UTF-8'

print "変換するコピックデータを指定してください:"
readfile = gets.chop.to_s

f=CSV.read("./#{readfile}.csv")     #ファイルオープン
puts xm.root{
  xm.comment! "コピックのRGBデータ"
  xm.copic{
    f.each{|info|
      if /(^+[A-Z]{1,2})/ =~ info[0] or /¥d{1,3}/ =~ info[0] then
        xm.color("type"=>$&){
          xm.name(info[2])
          xm.number(info[0])
          xm.rgbcode(info[1])
        }
      end
    }
  } 
}
print "ファイルネームを指定してください:"
filename = gets.chop.to_s
File.open("#{filename}.xml","w"){|xml|
  xml << xm
}

2012年11月3日土曜日

rvmでRubyをインストールする時の注意

事情あって複数バージョンのRuby環境を導入するはめになった。
rvmを利用します。MacBookAirにはデフォルトで用意されている。多分。

   $rvm list known
現在時点で実行すると以下の様なインストールできるリストが表示されます。
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7-p370
[ruby-]1.8.7[-p371]
[ruby-]1.9.1[-p431]
[ruby-]1.9.2-p180
[ruby-]1.9.2-p290
[ruby-]1.9.2-p318
[ruby-]1.9.2[-p320]
[ruby-]1.9.2-head
[ruby-]1.9.3-preview1
[ruby-]1.9.3-rc1
[ruby-]1.9.3-p0
[ruby-]1.9.3-p125
[ruby-]1.9.3-p194
[ruby-]1.9.3-[p286]
[ruby-]1.9.3-head
ruby-head

# GoRuby
goruby

# TheCodeShop - MRI experimental patches
tcs

# JRuby
jruby-1.2.0
jruby-1.3.1
jruby-1.4.0
jruby-1.6.5
jruby-1.6.5.1
jruby-1.6.6
jruby-1.6.7
jruby-1.6.7.2
jruby-1.6.8
jruby-[1.7.0]
jruby-head

# Rubinius
rbx-1.0.1
rbx-1.1.1
rbx-1.2.3
rbx-1.2.4
rbx[-head]
rbx-2.0.testing

# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]

# Kiji
kiji

# MagLev
maglev[-head]
maglev-1.0.0

# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head

# IronRuby -- Not implemented yet.
ironruby-0.9.3
ironruby-1.0-rc2
ironruby-head
Ruby1.8.6と1.8.7が必要だったので上記のリストを見ながら導入します。 []は省くことができるようです。
   $rvm install 1.8.6
No binary rubies available for: osx/10.7/x86_64/ruby-1.8.6-p420.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
The provided compiler '/usr/bin/gcc' is LLVM based, it is not yet fully supported by ruby and gems, please read `rvm requirements`.
怒られた…gccが気に喰わぬといった雰囲気です。いじりましたが以下の方法で解決できました。
$rvm install 1.8.6 --with-gcc=clang