在MySQL中渲染中文/ UTF8字符使用PuTTY&命令行客户端 [英] Rendering Chinese/UTF8 characters in MySQL Select using PuTTY & commandline client

查看:194
本文介绍了在MySQL中渲染中文/ UTF8字符使用PuTTY&命令行客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用PuTTY连接时,使用MySQL的普通命令行客户端连接到MySQL数据库,并使其正确显示包含非西方字符的UTF8字段,有没有什么好的,直接的方法来连接到MySQL数据库?

我的表格使用UTF8编码,在正常使用情况下,这些值来自Android应用程序,并由Android应用程序显示。问题在于,偶尔东西出错,当他们这样做时,我几乎不可能知道发生了什么事情,因为MySQL的命令行客户端强制将UTF8值强制转换为(似乎是)ISO-8859-1(即,准当在屏幕上显示随机乱码时)。对于什么是值得的,蟾蜍为MySQL(包括自由和测试版)似乎UTF8输出相同的方式。



在一个半相关说明,我最喜欢的等宽字体是Andale Mono(是的,我真的很喜欢强制消歧的0 / O和1 / L字符)。我很确定它不包含CJK字符。是否有任何(免费)实用工具可用于从一个Truetype字体(如Andale Mono)撕下较低的127或256个字符,并基于某些UTF8 CJK Truetype字体创建一个新的Truetype字体,以替换较低的127或256个字符与从Andale Mono翻译的字体数据?首先,你应该确保你的控制台编码设置为UTF-8。
使用PuTTY你需要在窗口>翻译中将字符集下拉菜单设置为UTF-8

第二个MySQL区分数据字符集和连接字符集。
当你的数据是UTF-8编码但你的连接字符集被设置为例如ISO-8859-1MySQL将自动转换输出。

永久设置字符集最简单的方法是用下面的方法更新你的客户端my.cnf: / p>

  [client] 
default-character-set = utf8

有关连接字符集的详细信息,您可以在这里找到:
http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html



当使用MySQL API函数(例如PHP客户端)时,您可以通过发送查询来设置连接字符集

  SET NAMES utf8 

MySQL API的各种实现也支持直接设置字符集。
例如 http://www.php.net/manual/en/mysqli.set -charset.php


Is there any good, straightforward way to connect to a MySQL database using MySQL's normal commandline client while connected using PuTTY and get it to render UTF8 fields that include non-Western characters properly?

My tables use UTF8 encoding, and in normal use the values come from an Android app and are displayed by an Android app. The problem is that occasionally, Things Go Wrong, and when they do, it's almost impossible for me to figure out what's going on because MySQL's commandline client forcibly casts UTF8 values to (what appears to be) ISO-8859-1 (ie, quasi-random gibberish when shown on the screen). For what it's worth, Toad for MySQL (both free and beta) seem to mangle UTF8 output the same way.

On a semi-related note, my favorite monospaced font is Andale Mono (yeah, I really like the forcibly-disambiguated 0/O and 1/l characters). I'm pretty sure it doesn't include CJK characters. Is there any (free) utility that can be used to rip the lower 127 or 256 characters from one Truetype font (like Andale Mono), and create a new Truetype font based on some UTF8 CJK Truetype font that replaces the lower 127 or 256 characters with the font data ripped from Andale Mono?

解决方案

First you should make sure that your console encoding is set to UTF-8. Using PuTTY you need to set the charset dropdown in "Window" > "Translation" to UTF-8

Second MySQL distincts the data charset and the connection charset. When your data is UTF-8 encoded but your connection charset is set to e.g. "ISO-8859-1" MySQL will automatically convert the output.

The easiest way to set the charsets permanently is to update your client my.cnf with the following:

[client]
default-character-set=utf8

Detailed information about the connection charset you can find here: http://dev.mysql.com/doc/refman/5.5/en/charset-connection.html

When using the MySQL API functions ( PHP client e.g. ) you can set the connection charset by sending the query

SET NAMES utf8

Various implementations of the MySQL API also support setting the charset directly. e.g. http://www.php.net/manual/en/mysqli.set-charset.php

这篇关于在MySQL中渲染中文/ UTF8字符使用PuTTY&命令行客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆