Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
- # so hopefully future tables will also pick up the right charset.
- require 'rubygems'
- require 'active_record'
- db = "your_database_name_here"
- sqlconn = ActiveRecord::Base.establish_connection(
- :adapter => "mysql",
- :host => "localhost",
- :username => "root",
- :password => "the_password",
- :database => db
- )
- conn = ActiveRecord::Base.send(sqlconn.adapter_method,sqlconn.config)
- conn.tables.each do |table|
- q = "ALTER TABLE #{table} CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci"
- puts q
- conn.execute q
- end
- conn.execute("ALTER DATABASE #{db} DEFAULT CHARACTER SET utf8 ;")
Add Comment
Please, Sign In to add comment