Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 07:00 AM
Harald Vajkonny
 
Posts: n/a
Default LOAD DATA INTO doesn't work correctly with utf8

Hello,

I would like to import data from a utf8-coded comma seperated file. I
created my database with "DEFAULT CHARACTER SET utf8 COLLATE
utf8_general_ci" and I started my mysql-client with the
--default-character-set=utf8 option. Nevertheless, when I input primary
key fields, which differ only in one umlaut character (e.g. "achten" and
"ächten") I get the following error message:

ERROR 1062 (23000): Duplicate entry 'ächten' for key 1

(Same thing happens when I try to manually INSERT the row.)

When I display my variable settings with "SHOW variables LIKE 'c%';" I receive the following result:


+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | latin1_swedish_ci |
| completion_type | 0 |
| concurrent_insert | 1 |
| connect_timeout | 5 |
+--------------------------+----------------------------+
14 rows in set (0.02 sec)

From this I conclude it is the server setting, which causes the trouble
here. When I manipulate the settings manually from the client (with "SET
character_set_server=utf8; SET collation_server=utf8_general_ci;") the
values do change, but not the behaviour. But this can be expected, since
the server is already up and running with the wrong settings.

Does anybody know how I restart my mysql-server with the correct
character and collation settings, if this is the cause for my problem,
or if there might be any other reason for it. My mysql version is
5.0.26-12, running on a Suse Linux 10.2.

Best regards,
H.

--
"Wouldn't the sentence 'I want to put a hyphen between the words Fish
and And and And and Chips in my Fish-And-Chips sign' have been clearer
if quotation marks had been placed before Fish, and between Fish and
and, and and and And, and And and and, and and and And, and And and
and, and and and Chips, as well as after Chips?"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 07:00 AM
Ananda Kumar
 
Posts: n/a
Default Re: LOAD DATA INTO doesn't work correctly with utf8

Before you import at the mysql prompt set below variables and then try again
to load

set session max_error_count=500000;
set session collation_database=latin1_swedish_ci;
set session character_set_database=latin1;

regards
anandkl


On 8/30/07, Harald Vajkonny <vajkonny@t-online.de> wrote:
>
> Hello,
>
> I would like to import data from a utf8-coded comma seperated file. I
> created my database with "DEFAULT CHARACTER SET utf8 COLLATE
> utf8_general_ci" and I started my mysql-client with the
> --default-character-set=utf8 option. Nevertheless, when I input primary
> key fields, which differ only in one umlaut character (e.g. "achten" and
> "ächten") I get the following error message:
>
> ERROR 1062 (23000): Duplicate entry 'ächten' for key 1
>
> (Same thing happens when I try to manually INSERT the row.)
>
> When I display my variable settings with "SHOW variables LIKE 'c%';" I
> receive the following result:
>
>
> +--------------------------+----------------------------+
> | Variable_name | Value |
> +--------------------------+----------------------------+
> | character_set_client | utf8 |
> | character_set_connection | utf8 |
> | character_set_database | utf8 |
> | character_set_filesystem | binary |
> | character_set_results | utf8 |
> | character_set_server | latin1 |
> | character_set_system | utf8 |
> | character_sets_dir | /usr/share/mysql/charsets/ |
> | collation_connection | utf8_general_ci |
> | collation_database | utf8_general_ci |
> | collation_server | latin1_swedish_ci |
> | completion_type | 0 |
> | concurrent_insert | 1 |
> | connect_timeout | 5 |
> +--------------------------+----------------------------+
> 14 rows in set (0.02 sec)
>
> From this I conclude it is the server setting, which causes the trouble
> here. When I manipulate the settings manually from the client (with "SET
> character_set_server=utf8; SET collation_server=utf8_general_ci;") the
> values do change, but not the behaviour. But this can be expected, since
> the server is already up and running with the wrong settings.
>
> Does anybody know how I restart my mysql-server with the correct
> character and collation settings, if this is the cause for my problem,
> or if there might be any other reason for it. My mysql version is
> 5.0.26-12, running on a Suse Linux 10.2.
>
> Best regards,
> H.
>
> --
> "Wouldn't the sentence 'I want to put a hyphen between the words Fish
> and And and And and Chips in my Fish-And-Chips sign' have been clearer
> if quotation marks had been placed before Fish, and between Fish and
> and, and and and And, and And and and, and and and And, and And and
> and, and and and Chips, as well as after Chips?"
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=anandkl@gmail.com
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 07:00 AM
Harald Vajkonny
 
Posts: n/a
Default Re: LOAD DATA INTO doesn't work correctly with utf8

Ananda Kumar schrieb:
> Before you import at the mysql prompt set below variables and then try
> again to load
>
> set session max_error_count=500000;
> set session collation_database=latin1_swedish_ci;
> set session character_set_database=latin1;

This is not what I need, because I use utf8 as well as in the database
as in the input file and I do not have any latin1 at all. When I choose
latin1 here, indeed, I don't receive an error message, but my data
becomes corrupted.

When, however, I choose "utf8" and "utf8_general_ci" as "session
character_set_database" and "session collation_database", I still get
the same error message.

Best regards,
H.


--
"Wouldn't the sentence 'I want to put a hyphen between the words Fish
and And and And and Chips in my Fish-And-Chips sign' have been clearer
if quotation marks had been placed before Fish, and between Fish and
and, and and and And, and And and and, and and and And, and And and
and, and and and Chips, as well as after Chips?"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 07:00 AM
Edward Kay
 
Posts: n/a
Default RE: LOAD DATA INTO doesn't work correctly with utf8

> I would like to import data from a utf8-coded comma seperated file. I
> created my database with "DEFAULT CHARACTER SET utf8 COLLATE
> utf8_general_ci" and I started my mysql-client with the
> --default-character-set=utf8 option. Nevertheless, when I input primary
> key fields, which differ only in one umlaut character (e.g. "achten" and
> "ächten") I get the following error message:
>
> ERROR 1062 (23000): Duplicate entry 'ächten' for key 1
>
> (Same thing happens when I try to manually INSERT the row.)
>
> When I display my variable settings with "SHOW variables LIKE
> 'c%';" I receive the following result:
>
>
> +--------------------------+----------------------------+
> | Variable_name | Value |
> +--------------------------+----------------------------+
> | character_set_client | utf8 |
> | character_set_connection | utf8 |
> | character_set_database | utf8 |
> | character_set_filesystem | binary |
> | character_set_results | utf8 |
> | character_set_server | latin1 |
> | character_set_system | utf8 |
> | character_sets_dir | /usr/share/mysql/charsets/ |
> | collation_connection | utf8_general_ci |
> | collation_database | utf8_general_ci |
> | collation_server | latin1_swedish_ci |
> | completion_type | 0 |
> | concurrent_insert | 1 |
> | connect_timeout | 5 |
> +--------------------------+----------------------------+
> 14 rows in set (0.02 sec)
>
> From this I conclude it is the server setting, which causes the trouble
> here. When I manipulate the settings manually from the client (with "SET
> character_set_server=utf8; SET collation_server=utf8_general_ci;") the
> values do change, but not the behaviour. But this can be expected, since
> the server is already up and running with the wrong settings.
>
> Does anybody know how I restart my mysql-server with the correct
> character and collation settings, if this is the cause for my problem,
> or if there might be any other reason for it. My mysql version is
> 5.0.26-12, running on a Suse Linux 10.2.
>
> Best regards,
> H.


Try using the SET NAMES 'utf8' statement [1] to tell MySQL that your client
is sending data in UTF-8. I believe that as your server is latin1, it will
assume this is the character set used by the command line client.

[1] http://dev.mysql.com/doc/refman/5.0/...onnection.html

Edward

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 07:00 AM
Harald Vajkonny
 
Posts: n/a
Default Re: LOAD DATA INTO doesn't work correctly with utf8

Edward Kay schrieb:
> Try using the SET NAMES 'utf8' statement [1] to tell MySQL that your client
> is sending data in UTF-8. I believe that as your server is latin1, it will
> assume this is the character set used by the command line client.
>
> [1] http://dev.mysql.com/doc/refman/5.0/...onnection.html
>
> Edward
>
>

I tried, but the behaviour remains the same. I guess my first option
should be to force the server to use utf8 as default. I would have no
problems in doing so, because I hardly use any latin1 anymore.

But how would I do so? The mysqld has some options for this, but I
didn't manage yet to simply restart it with new options, because it is
started somewhere in the init.d-procedure of my Linux system and even as
root I cannot simply invoke it from the command line.

Best regards,
Harald


--
"Wouldn't the sentence 'I want to put a hyphen between the words Fish
and And and And and Chips in my Fish-And-Chips sign' have been clearer
if quotation marks had been placed before Fish, and between Fish and
and, and and and And, and And and and, and and and And, and And and
and, and and and Chips, as well as after Chips?"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 07:00 AM
=?ISO-8859-15?Q?Du=A8an_Pavlica?=
 
Posts: n/a
Default Re: LOAD DATA INTO doesn't work correctly with utf8

Edward Kay napsal(a):
>> I would like to import data from a utf8-coded comma seperated file. I
>> created my database with "DEFAULT CHARACTER SET utf8 COLLATE
>> utf8_general_ci" and I started my mysql-client with the
>> --default-character-set=utf8 option. Nevertheless, when I input primary
>> key fields, which differ only in one umlaut character (e.g. "achten" and
>> "ächten") I get the following error message:
>>
>> ERROR 1062 (23000): Duplicate entry 'ächten' for key 1
>>
>> (Same thing happens when I try to manually INSERT the row.)
>>
>> When I display my variable settings with "SHOW variables LIKE
>> 'c%';" I receive the following result:
>>
>>
>> +--------------------------+----------------------------+
>> | Variable_name | Value |
>> +--------------------------+----------------------------+
>> | character_set_client | utf8 |
>> | character_set_connection | utf8 |
>> | character_set_database | utf8 |
>> | character_set_filesystem | binary |
>> | character_set_results | utf8 |
>> | character_set_server | latin1 |
>> | character_set_system | utf8 |
>> | character_sets_dir | /usr/share/mysql/charsets/ |
>> | collation_connection | utf8_general_ci |
>> | collation_database | utf8_general_ci |
>> | collation_server | latin1_swedish_ci |
>> | completion_type | 0 |
>> | concurrent_insert | 1 |
>> | connect_timeout | 5 |
>> +--------------------------+----------------------------+
>> 14 rows in set (0.02 sec)
>>
>> From this I conclude it is the server setting, which causes the trouble
>> here. When I manipulate the settings manually from the client (with "SET
>> character_set_server=utf8; SET collation_server=utf8_general_ci;") the
>> values do change, but not the behaviour. But this can be expected, since
>> the server is already up and running with the wrong settings.
>>
>> Does anybody know how I restart my mysql-server with the correct
>> character and collation settings, if this is the cause for my problem,
>> or if there might be any other reason for it. My mysql version is
>> 5.0.26-12, running on a Suse Linux 10.2.
>>
>> Best regards,
>> H.
>>

>
> Try using the SET NAMES 'utf8' statement [1] to tell MySQL that your client
> is sending data in UTF-8. I believe that as your server is latin1, it will
> assume this is the character set used by the command line client.
>
> [1] http://dev.mysql.com/doc/refman/5.0/...onnection.html
>
> Edward
>
>
>

From my experience SET NAMES doesn't work, but character set of the
database must be same as file's character set and this condition is OK.
For sure I used script:

USE database_with_correct_charset;
LOAD DATA ...;

And this worked fine for files with cp1250 and also with keybcs2 (I had
two databases, of course)

HTH,
Dusan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 07:00 AM
=?windows-1252?Q?Du=9Aan_Pavlica?=
 
Posts: n/a
Default Re: LOAD DATA INTO doesn't work correctly with utf8

Harald Vajkonny napsal(a):
> Dušan Pavlica schrieb:
>
>> Try to convert file to latin1, if it's possible, create database with
>> latin1 charset, create table with required structure (you can set utf8
>> charset to string fields ) and then load data.
>>

> I can not convert the file into latin1, because it is multilingual (i.e.
> European, Japanese, Korean etc.).
>
>
>> What client do you use to check whether data are OK? I can recommend
>> MySQL Query Browser where I don't have to care about setting charset
>> and collation parameters.
>>
>>

> I checked the file in MySQL Query Browser too, but even there I get it
> wrong, when I imported it with a latin session. I get it displayed
> right, when I import it with utf8, but then I have the message with
> duplicate keys and get only half of the data.
>

What's the charset and collation of your primary field in the table?

Dusan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 07:00 AM
Harald Vajkonny
 
Posts: n/a
Default Re: LOAD DATA INTO doesn't work correctly with utf8

Dušan Pavlica schrieb:
> What's the charset and collation of your primary field in the table?

With which command do I get the charset and collation information of a
single field in a table? SHOW CREATE TABLE returns:
....
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |

But I believe it is utf8, because when I enter Japanese or Russian text
in this field by INSERT it is displayed right. It just can't distinguish
between "a", "ä" or "á", but treats it as if they were "a".

In doing this I got another idea: Does anybody know the difference
between the collations utf8_general_ci, utf8_unicode_ci and utf8_bin?
I'll try these first and then get back to you about the results.

Best regards,
H.

--
"Wouldn't the sentence 'I want to put a hyphen between the words Fish
and And and And and Chips in my Fish-And-Chips sign' have been clearer
if quotation marks had been placed before Fish, and between Fish and
and, and and and And, and And and and, and and and And, and And and
and, and and and Chips, as well as after Chips?"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-28-2008, 07:00 AM
Harald Vajkonny
 
Posts: n/a
Default Re: [solved]LOAD DATA INTO doesn't work correctly with utf8

Harald Vajkonny schrieb:
> In doing this I got another idea: Does anybody know the difference
> between the collations utf8_general_ci, utf8_unicode_ci and utf8_bin?
> I'll try these first and then get back to you about the results.
>

That was it. If I choose utf8_bin as collation everything works fine!

Best regards,
H.

--
"Wouldn't the sentence 'I want to put a hyphen between the words Fish
and And and And and Chips in my Fish-And-Chips sign' have been clearer
if quotation marks had been placed before Fish, and between Fish and
and, and and and And, and And and and, and and and And, and And and
and, and and and Chips, as well as after Chips?"

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-28-2008, 07:00 AM
Ananda Kumar
 
Posts: n/a
Default Re: [solved]LOAD DATA INTO doesn't work correctly with utf8

Hi Harald,
So you set the

collation_database=utf8_bin, what was your character_set_database values.

regards
anandkl


On 8/30/07, Harald Vajkonny <vajkonny@t-online.de> wrote:
>
> Harald Vajkonny schrieb:
> > In doing this I got another idea: Does anybody know the difference
> > between the collations utf8_general_ci, utf8_unicode_ci and utf8_bin?
> > I'll try these first and then get back to you about the results.
> >

> That was it. If I choose utf8_bin as collation everything works fine!
>
> Best regards,
> H.
>
> --
> "Wouldn't the sentence 'I want to put a hyphen between the words Fish
> and And and And and Chips in my Fish-And-Chips sign' have been clearer
> if quotation marks had been placed before Fish, and between Fish and
> and, and and and And, and And and and, and and and And, and And and
> and, and and and Chips, as well as after Chips?"
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=anandkl@gmail.com
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:44 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
UnixAdminTalk.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476