Log in

View Full Version : change database from latin1 to UTF8


emath
10-20-2010, 11:18 AM
i want to change my database from latin1 to UTF8 , the ALL COLLATION .

i tried the latest version of vCharset and few other stuff like using this code :

<?php
// Don't forget to enter your db infos.

define('THIS_SCRIPT', 'convert');
require './global.php';

//---------------

header('Content-type: text/plain');

$dbconn = mysql_connect('localhost', 'name, '********' or die( mysql_error() );
mysql_select_db("emath_arielutf");

$sql = "ALTER DATABASE `name` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$result = mysql_query($sql) or die( mysql_error() );
print "Database changed to UTF-8.\n";

$sql = 'SHOW TABLES';
$result = mysql_query($sql) or die( mysql_error() );

while ( $row = mysql_fetch_row($result) )
{
$table = mysql_real_escape_string($row[0]);
$sql = "ALTER TABLE $table DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci, CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci";
mysql_query($sql) or die( mysql_error() );
print "$table changed to UTF-8.\n";
}

mysql_close($dbconn);
?>

tried also : http://en.gentoo-wiki.com/wiki/Convert_latin1_to_UTF-8_in_MySQL

any one have an idea how to do it perfectly?

im using vb3.8.6

thanks.

Konstantinos
10-23-2010, 08:24 AM
i did this and it was the most diffucult thing i ever did in my life. this vcharset is junk. i have a big db so in some tables the encoding process returned errors. i had to manually fix some ,

anyway i dont know how big is your db but u should check this out.

http://www.vbulletin.com/forum/showthread.php?320866-vB-4.0-UTF-8-support-Upgrade-from-3.8x&p=1816873&viewfull=1#post1816873

it will give u an idea on how to start, get a test forum and a dump and start testing importing etc. if any tables return errors try to exclude them from the dump, then encode the db with the excluded tables, and then if this happens i ll tell u what i did.

emath
10-26-2010, 06:29 AM
it didnt worked for me !
(i had many problems, after solveing them , i had a collation mix problem, so i converted all the collation also, and then after i successfully logged in my admin cp i didnt see hebrew , only english and gibbreish - although i used UTF8 encoded.. )

my db size is about 220MB .

anyone can make it clear once and for all how to do the convert?

so many people are looking for this .....

Konstantinos
10-26-2010, 11:33 AM
what was the problems u encountered ?

emath
10-26-2010, 11:40 AM
as i said, ive seen only english and gibbresh , no hebrew ...

Konstantinos
10-26-2010, 11:53 AM
u need to convert it 3 times then - from english to utf-8, from gibbresh to utf-8 and from hebrew to utf-8

3 times this command iconv -c -f windows-1252 -t utf-8 your-database.sql > your-database_utf8.sql

replacing windiws-1252 with the appropriate encoding for gibbresh and hebrew