Skip to content

Instantly share code, notes, and snippets.

@paulmars
Created November 3, 2015 17:58
Show Gist options
  • Select an option

  • Save paulmars/c7b738c60a431da1a16b to your computer and use it in GitHub Desktop.

Select an option

Save paulmars/c7b738c60a431da1a16b to your computer and use it in GitHub Desktop.
Convert all exists mysql tables to utf8.
databasename = "DBNAME"
ActiveRecord::Base.connection.tables.each do |table|
sql_string = "ALTER TABLE #{databasename}.#{table} CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;"
connection = ActiveRecord::Base.connection
connection.execute(sql_string)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment