Setting the database character set under Ubuntu

Source: Internet
Author: User
Tags locale mozilla thunderbird mozilla thunderbird mail thunderbird mail

In the Linux environment, the problem of database garbled, with Ubuntu as an example of the summary

Ubuntu Environment sets the character set utf8,windows the default character set is Gbk,ubuntu, which is the default character set of Utf-8, which makes garbled when logging on to a remote server with telnet or viewing Windows files. You need to set the Ubuntu environment to GBK or GB2312, or set the software to display the kanji correctly. The following is a description of the GBK character set as an example:

First, modify the Ubuntu default character set to GBK

1. First set sudo vi/var/lib/locales/supported.d/local
Adds a row of ZH_CN. GBK GBK
sudo locale-gen generate locale
2, modify the Ubuntu character set

    • Method One: Modify the. profile file in the user directory to add the following:

Language= "Zh_CN:zh:en_US:en"
Lang=zh_cn. GBK
You can log in again.
This method is valid only for that user.

    • Method Two: Modify the/etc/environment, add the following content:

Language= "Zh_CN:zh:en_US:en"
Lang=zh_cn. GBK
Then restart X to
This method is valid for users that do not have the Lang and language environment variables set

Second, set the software naming its normal display GBK

This requires the software itself to support multi-character encoding, the most common is IE and other browsers, you can set the encoding to display the GBK character set. Some software under Ubuntu also supports this feature, taking Ubuntu's terminal program as an example, so that its normal display GBK encoding method is:On The Termial window, click menu: Terminal, set character encoding, select GBK.
##########################################
Fix file name, mp3 tag, text file in Chinese garbled
Users who move from windows to Ubuntu often find that files they create/download/save under Windows are frequently garbled (Kubuntu is more likely to be problematic). When using the default player to open a previous music file (MP3, etc.), the chance of garbled is closer to 100%.
The solutions to these problems have been included in the Ubuntu use tips, but because of the universality of the problem, I think it is necessary to transfer here.
Convert file name from GBK to UTF8
sudo apt-get install CONVMV
Convmv-r-F cp936-t utf8–notest–nosmart *
Convert file contents from GBK to UTF8 iconv-f gbk-t UTF8 $i > NewFile
Convert MP3 tag encoding
sudo apt-get install Python-mutagen
Find. -iname "*.mp3"-execdir mid3iconv-e GBK {} \;
#####################################
Buntu the default open. txt file is gedit, gedit the default encoding is UTF8, and opening the gb2312 document under Windows Edit is garbled. One solution is to change the gedit code to GB2312, as follows:
Right-click on the Applications menu and select Editmenu. In the MainMenu dialog box, tick Systemtools-configurationeditor and open from the Applications menu.
Turn on/apps/gedit-2/preferences/encodings/Double-click on the right auto_detected, in the Pop-up dialog box, select Add, add values to GB2312, select after OK, click the Up button to move it to the first bit.
In the same way, the Show_in_menu is set and the GB2312 is placed first.
Another way is to open the. txt file with OpenOffice, which will let you choose the encoding, select GB2312 on the line.
***********************************************
1. System default encoding
We know that under the Chinese Windows generally speaking system default encoding is GBK, from the perspective of Java development, is to do such as Java source code compilation, file read and write operations, the default code used is GBK; We may recommend setting the default language to ZH_CN, as we refer to the General Ubuntu Chinese installation documentation.  UTF-8, this brings up some problems, such as the default encoding of my editor when I use Eclipse in Windows is GBK, but under Ubuntu is UTF-8, also using Eclipse, the Chinese document under Windows to Ubuntu will produce garbled, you must manually set the attributes of the document in the encoding for GBK to be normal; Some test code also reads the file with the default encoding, and the contents of the file read from the code will also contain garbled characters.
Therefore, it is best to set the system's default encoding to GBK, which is closest to the development environment under Windows. There should be more than one way to set it, I'm using the edit/etc/environment to look like this:
Language= "Zh_CN:zh:en_US:en"
Gst_id3_tag_encoding=gbk
Lang=zh_cn. GBK
Lc_ctyle=zh_cn. GBK
**********************************************
Ubuntu Chinese encoding settings
Today began to migrate the work environment to Linux, a day down, calm. Fortunately, in the first use of the Mozilla Thunderbird Mail client, rather than Outlook, this is simply too convenient, you can directly put hundreds of megabytes of mail directory copied to the Linux direct use, in stark contrast to the Microsoft's new version of Live Messager, today discovered that Microsoft's this thing does not even support installs on their own WinXP 64/wind2003/2008 above? I have nothing to say.
Ubuntu defaults to UTF8 encoding, which makes it easy to use global. But the Chinese language support, is not meticulous, even if the default installation in Chinese, will not automatically add gb* and other support, resulting in Ubuntu access to some of the win text files, garbled.
I. Configuring the SYSTEM Environment
Execute sudo vi/var/lib/locales/supported.d/zh
Add the following configuration parameters
Zh_cn. GB18030 GB18030 (latest Chinese character coded character set, backwards compatible with gbk,gb2312)
Zh_cn. GBK GBK (Chinese character extension code, backwards compatible GB2312, and contains BIG5 all kanji)
Zh_cn. GB2312 GB2312 (simplified characters coded character set, recently have customers want us to improve GB2312, too see us, I can only say: "no!")
Zh_cn.     GB18031 GB18031 (Digital keypad Chinese character coding input, for handheld devices, my Nokia3120 is always texting, answering the phone, unable to communicate with the PC, this is not necessary. Maybe the heroes who use Google's Android SDK need this)
Zh_hk. BIG5 BIG5 (Traditional)
Zh_tw. BIG5 BIG5 (Traditional)
Then execute sudo locale-gen
Prompt for the following information, succeeded
Zh_cn. GB18030 ... done
Zh_cn. GBK ... done
......
II. System environment support gb* inside the code, but with VI, gedit and other tools to access the file will continue garbled, need to be configured for different tools, so that their own detection support within the range of coding
e.g. VI
Execute sudo vi/etc/vim/vimrc
Add the following configuration parameters
Let &termencoding=&encoding
Set Fileencodings=utf-8,gb18030,gbk,gb2312,big5
e.g. gedit
Execute sudo gconf-editor
Select Apps/gedit-2/preferences/encodings
Find auto_detected Editor, add Gb18030,gbk,gb2312,big5 in values

Setting the database character set under Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.