Bug #31292 output from mysql --execute "select .." does not support unicode
Submitted: 29 Sep 2007 14:40 Modified: 8 Oct 2007 5:52
Reporter: Peter Laursen (Basic Quality Contributor) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Charsets Severity:S2 (Serious)
Version:5.0.45 OS:Windows
Assigned to: CPU Architecture:Any
Tags: qc

[29 Sep 2007 14:40] Peter Laursen
Description:
This is just another example of insufficent unicode (file) support in MySQL on Windows.  Another one was this: http://bugs.mysql.com/bug.php?id=29323

SELECT ONTO OUTFILE does not create a unicode (UTF8 or UTF16) file when in is necessary.  Always tries to create ANSI encoded files!

How to repeat:
Import attached dump.

select * into outfile 'c:\\uni.sql' from qwerty;

Client reports that it exported.   But file cannot be found (at least not on Vista)!  Looks like NTFS filesystem was violated.  

Try again

select * into outfile 'c:\\uni.sql' from qwerty;

"File allready exists" .. but it cannot be found!

Actually .. do I now have a system that is damaged (certains file paths not usable any more) and cannot be repaired ??

Suggested fix:
If it is not possble to change dynamically between ANSI and Unicode, then always use UTF8 or UTF16.
[29 Sep 2007 14:42] Peter Laursen
small dump with identifiers and data that requires unicode

Attachment: uni.sql (application/octet-stream, text), 1.15 KiB.

[29 Sep 2007 14:44] Peter Laursen
changing OS from 'any' ot Windows!
[29 Sep 2007 17:08] Valeriy Kravchuk
Thank you for a problem report. What exact version of MySQL server you had used?
[29 Sep 2007 18:31] Peter Laursen
sorry .. forgot that. And it was a good point actually!

I forgot I was connected to a remote Linux server.  The file was created on the server in var/lib/mysql folder!

This is not reproducable when connected to 5.1.18, 5.0.45 and 4.1.22 on 'localhost' (Windows).  File created is UTF8-encoded with the data of this example.

So 'not a bug' ...
[30 Sep 2007 21:41] Peter Laursen
same test case!

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql  -u root -p  --execute "select
 * from test.qwerty" > c:\tst.sql
Enter password: ********

C:\Program Files\MySQL\MySQL Server 5.0\bin>
[30 Sep 2007 21:42] Peter Laursen
file is ANSI encoded!

Attachment: tst.sql (application/octet-stream, text), 118 bytes.

[8 Oct 2007 5:52] Alexander Barkov
If you want utf8 output, you need to specify it in either command line:

mysql --default-character-set=utf8  -u root -p  --execute "select * from test.qwerty" > c:\tst.sql

or if you prefer utf8 by default, you can put this option into your my.cnf file.

This is not a bug. Everything works according to design.