Guest User

Untitled

a guest
May 28th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. # change the your_database_name_here bit, save this as some_file.rb, and ruby some_file.rb. changes all tables in db to utf-8, then changes the default for the db itself to utf-8
  2. # so hopefully future tables will also pick up the right charset.
  3. require 'rubygems'
  4. require 'active_record'
  5.  
  6. db = "your_database_name_here"
  7.  
  8. sqlconn = ActiveRecord::Base.establish_connection(
  9. :adapter => "mysql",
  10. :host => "localhost",
  11. :username => "root",
  12. :password => "the_password",
  13. :database => db
  14. )
  15.  
  16. conn = ActiveRecord::Base.send(sqlconn.adapter_method,sqlconn.config)
  17.  
  18. conn.tables.each do |table|
  19. q = "ALTER TABLE #{table} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"
  20. puts q
  21. conn.execute q
  22. end
  23. conn.execute("ALTER DATABASE #{db} DEFAULT CHARACTER SET utf8 ;")
Add Comment
Please, Sign In to add comment