Vim, Putty, SSH and MySQL in UTF-8 and Chinese Ideograms Display
Created: Friday, October 14, 2011 20:36:00
Vim or vi in a Lenny Debian Linux session is configured in a native way on ISO-Latin1 charset. Until today, Unix OS in general, as well as other console programs like MsDos, MySQL native client (mysql.exe) are not yet intrinsically in Unicode. It's not easy to visualize UTF-8 text for multi-byte files such as chinese writings.
The webmasters manage their Debian Linux Server at distance via a SSH session by PuTTY program from Windows 7 system, for example.
But a Chinese Windows is not required to show chinese ideograms, we can do it under Occidental Windows, French or English version.
At the Linux Side
One must install UTF-8 locales, the chinese fonts and modify the configuration ~/.vmimrc.
At the Windows 7 side, Windows Vista, Windows XP
The modern Windows is by default conforming to the UTF-8 norm, one has nothing to do for UTF-8 Locales under Windows. Nor for the character fonts, since the UTF-8 font is installed by default: Arial under Windows Microsoft. The Arial font can fill the role, even though it is nor ideal, since this font is not of constant pitch for every alphabet, this is not favorable to coding in programming, in English, in French for example. But for the first step, it's sufficient.
Now you are connected to your Linux host at distance.
More Chinese on vi, vim
The ordre of the configuration has no importance. You can start by the Linux side, or by the Windows 7 side. Moreover, to simply display chinese ideograms on vim, you have no need to define the accurate locale by yourselves, the genuin Linux does it for you.
If you would like to also have a Chinese vim interface, you must define the locale via the global Shell variable $LANG among the following possibilities:
Please note that for each locale separated by a space, the only first part is the valid locale name, for example, here is a good declaration:
# export LANG="zh_CN.UTF-8"
With this setting, the SHELL interface is also in the language zh_CN.UTF-8, who shows the system messages in Chinese. Here are some test commands run and ressults shown:
# date # df # ls nonexistent.file.
MySQL Native Client and Chinese
This setting is also valid for the native client of MySQL /usr/bin/mysql. To display contents stocked in Simplified chinese in a table, you run mysql by
# mysql --default-character-set=utf8 -u<unsername> -p<password> <your_dbname>Or you launch mysql without the option --default-character-set, then under the MySQL console, do a special definition query
mysql> SET NAMES 'utf8' COLLATE utf8_general_ci;. And then under the MySQL console, launch the query like
mysql> SELECT NameCn FROM products WHERE (ID=358);. The Chinese characters will be displayed in the result.
MySQL Native Client and Chinese in Windows
It's impossible to show UTF-8 Chinese in the MySQL native client mysql.exe, since it's launched by the Shell, here cmd32.exe or MS-DOS. MS-DOS does not accept Asian UTF-8 fonts for the standard terminal, no matter it is FangSong, SimSun... MySQL is so limited to Ms-DOS terminal fonts approved by Microsoft: Raster Terminal, TrueType Lucida Console, Consolas that offer no chinese ideogram. Even if one modifies Windows Register, there is any effect for the Chinese Fonts. And changing the Code Page as Unicode: After all this hard work, in the MySQL console, the chinese ideograms still appear in Hollow Square. This means that the font is Unicode, which supports the encoding of Chinese characters, but in which the glyphs, here the chinese ideograms are not drawn by the creator of the loaded font. To show Simplified Chinese contents stored in a MySQL table, you should use MySQL GUI Administrator Tools that is a FreeWare MySQL GUI Administrator Tools. Or by PHPMyAdmin via a Browser.