Method 1;
Log in to MySQL, do set names latin1 first;
The premise is that your created table is the (Engine=myisam DEFAULT charset=latin1) latin1 character set.
If your watch is GBK, set names GBK;
This method is temporary, that is, each time you log in to set names Latin1
The following methods are also subject to this premise
Ways to see what kind of character set a table is
Mysql> Show CREATE TABLE lvnian\g;
1. Row ***************************
Table:lvnian
Create table:create Table ' Lvnian ' (
' ID ' int (4) is not NULL,
' Name ' char (not NULL)
) Engine=myisam DEFAULT charset=latin1
1 row in Set (0.00 sec)
ERROR:
No query specified
Method 2
Set names latin1 in the SQL file, and then log in to MySQL by executing the following command
Cat > Test.sql<<eof
Set name Latin1;
INSERT into Lvnian values (4, ' Xiao Wang ');
Eof
Log in to MySQL and execute the following command
SOURCE Test.sql
Method 3
Set names latin1 in the SQL file, and then log in to MySQL by executing the following command
Cat > Test.sql<<eof
Set name Latin1;
INSERT into Lvnian values (4, ' Xiao Wang ');
Eof
Log in to MySQL and execute the following command
Mysql-uroot-p "Lvnian" Lvnian < Test.sql
Mysql-uroot-p "Lvnian"-E "set name Latin1;select * from Lvnian.lvnian"
Method 4
Implement--default-character-set=latin1 by specifying the mysql command character set parameter
Cat > Test.sql<<eof
INSERT into Lvnian values (4, ' Xiao Wang ');
Eof
====
Mysql-uroot-p "Lvnian"--default-character-set=latin1 Lvnian < Test.sql
Mysql-uroot-p "Lvnian"-E "set name Latin1;select * from Lvnian.lvnian"
Method 5
Setting the parameters of the client and server in the configuration file
Change the parameters of the MY.CNF client module to achieve the effect of set names Latin1 and to take effect permanently
[Client]
Default-character-set=latin1
Promotion: Modify the client's profile without restarting the service, save postpone re-login MySQL will take effect, equivalent to set names Latin1
Changing the service side
[Mysqld]
Default-character-set=latin1 # #适合5.1 version
Character-set-server=latin1 # #适合5.5 version
###########################################################################
Guaranteed not garbled thought:
MySQL client, MySQL server, library, table, program, system character set are all consistent and not garbled
Linux system Character Set modification place
[Email protected] ~]# cat/etc/sysconfig/i18n
Lang= "en_US. UTF-8 "
Sysfont= "Latarcyrheb-sun16"
[Email protected] ~]#
Client Character Set
Temporary entry into force
Set names UTF8 # #这个就是在修改客户端字符集
Or
The following is a permanent entry
[Client]
Default-character-set=utf8
Service-side Character set
[Mysqld]
Default-character-set=utf8 # #适合5.1 version
Character-set-server=utf8 # #适合5.5 version
Library table
Create DATABASE Lvnian default character set UTF8
CREATE TABLE ' Lvnian1 ' (
' ID ' int (4) is not NULL,
' Name ' char (not NULL)
) Engine=myisam DEFAULT charset=latin1;
View proofing rules for character types
mysql> SHOW Character set;
+----------+-----------------------------+---------------------+--------+
| Charset | Description | Default Collation | MaxLen |
+----------+-----------------------------+---------------------+--------+
| Big5 | Big5 Traditional Chinese | Big5_chinese_ci | 2 |
| Dec8 | DEC West European | Dec8_swedish_ci | 1 |
| cp850 | DOS West European | Cp850_general_ci | 1 |
| HP8 | HP West European | Hp8_english_ci | 1 |
| koi8r | Koi8-r relcom Russian | Koi8r_general_ci | 1 |
| Latin1 | cp1252 West European | Latin1_swedish_ci | 1 |
| latin2 | ISO 8859-2 Central European | Latin2_general_ci | 1 |
| Swe7 | 7bit Swedish | Swe7_swedish_ci | 1 |
| ASCII | US ASCII | Ascii_general_ci | 1 |
| Ujis | EUC-JP Japanese | Ujis_japanese_ci | 3 |
| Sjis | Shift-jis Japanese | Sjis_japanese_ci | 2 |
| Hebrew | ISO 8859-8 Hebrew | Hebrew_general_ci | 1 |
| tis620 | TIS620 Thai | Tis620_thai_ci | 1 |
| Euckr | EUC-KR Korean | Euckr_korean_ci | 2 |
| koi8u | Koi8-u Ukrainian | Koi8u_general_ci | 1 |
| gb2312 | GB2312 Simplified Chinese | Gb2312_chinese_ci | 2 |
| Greek | ISO 8859-7 Greek | Greek_general_ci | 1 |
| cp1250 | Windows Central European | Cp1250_general_ci | 1 |
| GBK | GBK Simplified Chinese | Gbk_chinese_ci | 2 |
| Latin5 | ISO 8859-9 Turkish | Latin5_turkish_ci | 1 |
| Armscii8 | ARMSCII-8 Armenian | Armscii8_general_ci | 1 |
| UTF8 | UTF-8 Unicode | Utf8_general_ci | 3 |
| UCS2 | UCS-2 Unicode | Ucs2_general_ci | 2 |
| cp866 | DOS Russian | Cp866_general_ci | 1 |
| KEYBCS2 | DOS Kamenicky Czech-slovak | Keybcs2_general_ci | 1 |
| Macce | Mac Central European | Macce_general_ci | 1 |
| Macroman | Mac West European | Macroman_general_ci | 1 |
| cp852 | DOS Central European | Cp852_general_ci | 1 |
| latin7 | ISO 8859-13 Baltic | Latin7_general_ci | 1 |
| cp1251 | Windows Cyrillic | Cp1251_general_ci | 1 |
| cp1256 | Windows Arabic | Cp1256_general_ci | 1 |
| cp1257 | Windows Baltic | Cp1257_general_ci | 1 |
| binary | Binary Pseudo CharSet | binary | 1 |
| Geostd8 | GEOSTD8 Georgian | Geostd8_general_ci | 1 |
| cp932 | SJIS for Windows Japanese | Cp932_japanese_ci | 2 |
| Eucjpms | Ujis for Windows Japanese | Eucjpms_japanese_ci | 3 |
+----------+-----------------------------+---------------------+--------+
$ rows in Set (0.00 sec)
Mysql>
This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1699347
MySQL does not garbled five ways