Project

General

Profile

Actions

Defect #5793

closed

Use utf8 character sets and collations in mysql

Added by Aleksandar Pavic over 13 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
Database
Target version:
-
Start date:
2010-07-01
Due date:
% Done:

0%

Estimated time:
Resolution:
Invalid
Affected version:

Description

Well I don't know is this really a defect, but I had to change collations to utf8_general_ci, and character set to utf8 to use latin characters.

After that everything worked as charm.

Actions #1

Updated by Felix Schäfer over 13 years ago

  • Status changed from New to Closed
  • Resolution set to Invalid

Redmine uses UTF-8 out of the box, MySQL doesn't create tables in UTF-8 out of the box but that is also described in the MySQL-specific part of the installation.

Actions #2

Updated by Jérémy Lal over 13 years ago

  • Status changed from Closed to Reopened

It could be improved, though :
doing a pristine install, when database.yml contains encoding: utf8
all data recorded to mysql is properly encoded,
EXCEPT for the data that is loaded by redmine:load_default_data task.

Actions #3

Updated by Jérémy Lal over 13 years ago

i meant when default database encoding is Latin, rails encoding utf8
makes sure table are utf8, except for the ones that corresponds to the data
loaded by load_default_data task.

Actions #4

Updated by Felix Schäfer over 13 years ago

Jérémy Lal wrote:

i meant when default database encoding is Latin, rails encoding utf8
makes sure table are utf8, except for the ones that corresponds to the data
loaded by load_default_data task.

Rails doesn't do nothing, saying encoding: utf8 in the database.yml just makes sure rails sends the data as UTF-8 to the DB engine. If the DB engine is configured with latin1 as collation, rails can't do anything against it.

Could you please describe what exactly you have done to get that error on a pristine install?

Actions #5

Updated by Jérémy Lal over 13 years ago

Hi,
this is probably not a bug, sorry.
Still, rake db:create or db:migrate could use
CREATE TABLE roles (...) DEFAULT CHARACTER SET utf8;
and that would solve the problem of mysql db created in latin1 (by default on most mysql installs).

Actions #6

Updated by Jérémy Lal over 13 years ago

The trouble is postgres, sqlite has been defaulting to UTF8 for quite a long time,
while mysql has still some weird encoding as its default. So most postgres or sqlite
users won't be bothered, while many mysql users will.
The following patch (added to config/initializers/) could help,
by creating tables with default charset utf8, regardless of the character_set_database.

require 'active_record'
require 'active_record/connection_adapters/abstract_adapter'
module ActiveRecord
  module ConnectionAdapters
    class MysqlAdapter < AbstractAdapter
      def create_table(table_name, options = {}) #:nodoc:
        encoding = @config[:encoding]
        if encoding
          options = options.reverse_merge(:options => "DEFAULT CHARSET=#{encoding}")
        end
        super(table_name, options.reverse_merge(:options => "ENGINE=InnoDB"))
      end
    end
  end
end

The patch consists in adding the three lines [if ... end].

Feel free to close the bug as invalid,
Jérémy.

Actions #7

Updated by Felix Schäfer over 13 years ago

  • Status changed from Reopened to Closed

Jérémy Lal wrote:

Still, rake db:create or db:migrate could use
CREATE TABLE roles (...) DEFAULT CHARACTER SET utf8;
and that would solve the problem of mysql db created in latin1 (by default on most mysql installs).

Then it's something you should report and discuss with the rails team and/or the maintainer of the mysql gem :-) The docs make it clear you should use mysql with UTF-8 as the collation, I don't think we need (yet another…) rails core patch for that.

Actions

Also available in: Atom PDF