Windows下mysql命令行工具插入和显示中文数据

my.ini里client和mysqld都设置了default-character-set=utf8
数据库和表的默认字符集也都是utf8,用MySQL Query Browser工具插入和查询中文输入没有问题,但直接在命令提示符里用mysql工具插入和查询有中文乱码。

与 http://www.javaworld.com.tw/jute/post/view?bid=21&id=128513&sty=1&tpg=1&age=0 里说的一样,好像win下mysql命令行工具不认。

解决办法:
插入数据前,set names utf8;
执行查询前,set name gbk;

4 thoughts on “Windows下mysql命令行工具插入和显示中文数据

  1. 我的也是一样的
    windows xp sp3
    mysql 字符集设的是 utf8, 命令行查询乱码
    表是django创建的,其他都照你说的做了。。。

    pS:在 Ubuntu下把没问题的

  2. 对了,刚才开了下表也是utf8的
    用 show create table tablename; 看的
    显示 DEFAULT CHARSET=utf8

Leave a Reply

Your email address will not be published. Required fields are marked *

*

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.
For more help see http://daringfireball.net/projects/markdown/syntax

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>