views:

37

answers:

3

Locally I do this to dump and move a database, upgrading silverstripe 2.3 to 2.4:

mysqldump --opt  --default-character-set=latin1 --skip-set-charset --user=$root -p$password $oldDatabase -r db.sql  

iconv -f LATIN1 -t UTF8 db.sql > db_utf.sql 


CREATE DATABASE $newDatabase CHARACTER SET utf8 COLLATE utf8_swedish_ci; FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON $newDatabase . * TO '$newUser'@'localhost';  FLUSH PRIVILEGES;
SET NAMES utf8; SOURCE db_utf.sql;

And it works, but on the server Ubuntu 8.04, with mysql Ver 14.12 Distrib 5.0.51a. I get crazy √∏ charterers instead of øæåØÆå.

Anyone know where I've gone wrong?

A: 

Have you tried it without the iconv step?

Here's what I use when dumping UTF-8 databases:

mysqldump \
    -u $DB_USER -p"$DB_PASS" \
    --default-character-set=Latin1 \
    --result-file=$DATAFILE

And to restore:

mysql -u $DB_USER -p"$DB_PASS" \
    --default-character-set=latin1 < $DATAFILE
Mike
Still skewed up characters are in the db.sql file! Ã where å should be.
Mario Michelli
looks like this may be the answer: http://www.vierundsechzig.de/blog/?p=323
Mario Michelli
Or not, I'm so lost.
Mario Michelli
How are you checking the output file? Not all text editors are UTF-8 compatible, so may display a correct file incorrectly.
Mike
textmate and vim.
Mario Michelli
A: 

Perhaps just copy the tables to $newDatabase as latin1. Then, for each table, execute:

ALTER TABLE table CONVERT TO CHARACTER SET utf8 COLLATE utf8_swedish_ci
unutbu
I've been looking at the mysqldump and no matter what default-character-set I use I get encoded letters:Ã. But if I look at the same data in mysql the letters are fine ø; So the problem is getting the data out not putting it in.
Mario Michelli
Can you stop mysql temporarily with `sudo invoke-rc.d mysql stop` ? Or are you on some production server which must not stop? If you can stop mysql, you can directly copy the database in /var/lib/mysql. Once you've backed that up, restart mysql with `sudo invoke-rc.d mysql start` and then perhaps you can try the `ALTER TABLE` command above directly on the current database tables. It should convert you to utf8 without using `mysqldump`.
unutbu
maybe the best solution, thank you.
Mario Michelli
A: 

Because I wanted to back up the current database before an upgrade. mysqlhotcopy is a solution that worked for me (thanks unutbu).

http://dev.mysql.com/doc/refman/5.0/en/mysqlhotcopy.html

Mario Michelli