[LRUG] MySQL/Rails Collation

Andrew Stewart boss at airbladesoftware.com
Tue Jan 24 01:00:24 PST 2012


On 23 Jan 2012, at 18:21, mudge wrote:
> Having gone through much pain with incorrect encodings with Rails and
> MySQL in the past, I highly recommend you read Aleksandar's link as it
> highlights an important issue: if you have been storing UTF-8 data in
> a non-UTF-8 table then when changing encoding, MySQL will attempt to
> translate your data (which, in this case, would be incorrect as it is
> already UTF-8) which can result in corruption.

Thanks for that link and all the advice -- much appreciated.

Step 1 on that blog post is to export the data as latin1.  I noticed the header of my dump file looks like:

    -- MySQL dump 10.13  Distrib 5.1.41, for debian-linux-gnu (x86_64)
    --
    -- Host: localhost    Database: lolmysql_production
    -- ------------------------------------------------------
    -- Server version	5.1.41-3ubuntu12.10-log
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;

The dump file goes on to define tables like this:

    DROP TABLE IF EXISTS `accounts`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `accounts` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `subdomain` varchar(255) DEFAULT NULL,
      `created_at` datetime DEFAULT NULL,
      `updated_at` datetime DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=56 DEFAULT CHARSET=latin1;

Is this exporting the data as latin1 or as utf8?

Cheers,
Andy

-------
http://airbladesoftware.com


More information about the Chat mailing list