Skip to content

Instantly share code, notes, and snippets.

@dchentech
Created July 9, 2010 03:57
Show Gist options
  • Save dchentech/469012 to your computer and use it in GitHub Desktop.
Save dchentech/469012 to your computer and use it in GitHub Desktop.
# 把部分latin1编码的mysql表转化为UTF8编码
ActiveRecord::Base.connection.tables.select do |t|
ActiveRecord::Base.connection.execute("show create table #{t}").to_a[0][1].match(/CHARSET=latin1/)
end.each do |t|
ActiveRecord::Base.connection.execute("alter table #{t} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment