Slashdot Log In
Migrate a MySQL Database Preserving Special Characters
Posted by
kdawson
on Mon May 07, 2007 12:30 AM
from the encoding-juju dept.
from the encoding-juju dept.
TomSlick writes "Michael Chu's blog provides a good solution for people migrating their MySQL databases and finding that special characters (like smart quotes) get mangled. He presents two practical solutions to migrating the database properly."
This discussion has been archived.
No new comments can be posted.
Migrate a MySQL Database Preserving Special Characters
|
Log In/Create an Account
| Top
| 98 comments
| Search Discussion
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.

Migration (Score:4, Informative)
(http://fetter.org/~shackle/)
Useful? This is damned awesome! (Score:2)
Re:Useful? This is damned awesome! (Score:5, Informative)
http://www.joelonsoftware.com/articles/Unicode.ht
The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)
Big Trouble in Little China. Don't use UCS-2. (Score:5, Informative)
(http://www.scarydevil.com/~peter/ | Last Journal: Monday September 26 2005, @06:53PM)
In other words, Joel has made the same mistake as the people who wrote software that only works in 7-bit ASCII or 8-bit UTF-8 or the IBM or Apple or Adobe 8-bit extended ASCII sets or the 9-bit extended ASCII set that ITS used, or...
And it's already too late to try and cram everything into 2 bytes. After the Han Unification mess (the attempt to force Chinese and Japanese and everything else that used some variant of Chinese ideograms (Kanji, etc...) into a common subset of similar characters that fit in the 65535 available codes in the BMP) the People Republic of China decided to require their computers to support their national encoding anyway. As of 2000.
So you have to support the full UCS encoding anyway.
There's three storage formats that it's practical to use: UCS-4 (4 bytes per character, with the same byte-ordering problems as UCS-2), UTF-16 (2-4 bytes per character, same as UCS-2 for the BMP) or UTF-8 (1-4 bytes per character). Internally: you can use UCS-4 as your wide character type, and translate on the fly; use UTF-8 and use care to avoid breaking strings in the middle of glyphs or use UTF-16 and translate on the fly and use care to avoid breaking strings in the middle of glyphs.
If Joel is lucky the libraries he's using are actually operating on UTF-16 strings instead of UCS-2 strings. If he's *really* lucky they're designed to avoid breaking up codes outside the BMP. If he's *super* lucky he's managed to avoid creating any code that just operates on strings as a stream of wchar_t anywhere.
Personally, I think that UTF-16 gets you the worst of both worlds: your data is almost certainly less compact than if you use UTF-8; you still have to deal with multi-wchar_t strings so your code is no easier to write than if you used UTF-8... you're just less likely to find bugs in testing; and you get byte order issues in files just like you would with UCS-4. Unless you think UCS-2 is "good enough" and you just ignore everything outside the BMP and discover that people in China are suddenly getting hash when they use your program.
Small teapot in Big China. UCS-2 slices and dices. (Score:4, Interesting)
My one criticism of Joel was passing himself the "get out of jail free" card. Before I get started, I should warn you that if you are one of those rare people who knows about internationalization, you are going to find my entire discussion a little bit oversimplified. This is a fair disclaimer, but it makes it impossible to judge where Joel was simplifying deliberately and where he simplified because he didn't know any better. The correction would be for Joel to state "I'm going to simplify issues X, Y, and Zed". Then mistakes in the middle of the alphabet would be entirely his own. Just as there is no such thing as a string without a coding system, there is no such thing as a useful disclaimer that doesn't specify precisely what it disclaims. It amused me to see Joel invoke the ASCII standard of accountability.
Concerning the claim that Joel has made the same mistake [over again], this same claim comes up all the time concerning address arithmetic. How much existing code is portable to a 128 bit address size? We're sure to need this by 2050. Or perhaps not. People tend to neglect the observation that we're talking about a doubly exponential progression in codespace: (2^2^3)^2^N, with the values N=0,1,2,3,4 plausible in photolithographic solid state. On the current progression, for N=5 transistors would need to be subatomic. As far as the present transition from 32 bits to 64 bits of address space, it makes sense that operating systems and file systems are 64-bit native, while 99% of user space applications continue to run in less time and space compiled for 32 bits. Among the growing sliver of applications that do run better in 64-bits are a few applications of especially high importance.
I worked extensively with CJK languages in the early 1990s, and my opinion at the time was that UCS-4 primarily catered to the SETI crowd, and potentially, belligerent Mandarins in mainland China. I recall more argument at the time about Korean, which is a syllabic script masquerading as ideographic blocks.
http://en.wikipedia.org/wiki/Hangul [wikipedia.org]
I've always had a lot of trouble understanding the opposition to Han unification. Many distinctions in the origins of the English language were lost in the adoption of ASCII, such as the ae ligature and the old-English thorn (which causes many Hollywood sets to feature "Ye old saloon").
http://en.wikipedia.org/wiki/Han_unification [wikipedia.org]
http://en.wikipedia.org/wiki/Thorn_(letter) [wikipedia.org]
And all this fits quite nicely in UCS-2 as advocated by Joel.
Pffft Easy... (Score:5, Funny)
Then you create these tables in the new one. Just so there are no problems with data types you should probably just make every field varchar(100) in the new one.
Then you fire up MS Access, the older the better. I try to stick to Access 95.
Then you create two ODBC links, one to your old one and one to the new one.
Then you use the linked table manager to link each table to ms access.
Then you open both the new table and the old table and select all, copy and paste the data into the new table.
It's so simple even a child could do it!
Re:Pffft Easy... (Score:4, Funny)
(Last Journal: Tuesday December 30 2003, @07:51AM)
How is this news? (Score:1)
Re:How is this news? (Score:5, Funny)
(http://kestas.kuliukas.com/)
Unicode integration woes (Score:5, Interesting)
(http://127.0.0.1/I_h4x0r_j00r_cpu | Last Journal: Friday August 24, @06:57PM)
That bit me one time when one of my live servers crashed and I had to load the data on the backup onto a different server. I remember wondering to myself, when was the good old days when a database was a dumb (smart, depending your POV) engine that only worries about a string of bytes (chars). Seriously, it only should become smarter and start talking in unicode only when I want it to.
Issues with using unicode is not just limited to MySQL, as Python have similar issues. However they are almost always caused by poor programmers who mixes usage between the two, or not doing type checking on the proper type (basestring).
mysqldump is too think (Score:3, Interesting)
What's with the sudden influx of gnubies? (Score:5, Insightful)
If you do insert unicode data into a latin1 table, you will get unexpected results.
What you do is make sure that your:
a) database(s) are set to utf8 by default
b) table(s) are set to utf8 by default
c) column(s) are set to utf8 by default
d) connection defaults to utf8
(provided, of course, that it's utf8 you're after)
That way, it'll "Just Work"(tm)
We've gone through upgrades from 3.23 -> 4.0 -> 4.1 -> 5.0 and never had a problem; and yes, our tables were all latin1 from the beginning.
Tagged slashdigg (Score:2)
NEWS: Slashdot bought by webnoobs.com (Score:1)
(http://www.lost.eu/68bf7)
Oh & you can change the encoding at anytime, so even if you initially forget you just change it later, then dump.
Why use mysqldump? Why not just scp+mysqlrepair ? (Score:1)
http://www.seanodonnell.com/code/?id=66 [seanodonnell.com]
That process prevents the syntax conversion issues, storage and bandwidth requirements, and processing-time requirements caused by using mysqldump.
Re:how about ... (Score:3, Informative)
Re:smart quotes? more like stupid fucked up quotes (Score:2)
(Last Journal: Wednesday January 31 2007, @02:25AM)