First post:
Original address:
Linux server under File name my.cnf
Windows under File name My.ini
problem: When adding Chinese data to the database through the SQL language, the query is garbled. Cause: The original installation database is the default encoding is LATIN1 encoding (Latin1 is the ISO-8859-1 aliases, some environment writing latin-1Resolution: I am talking about latin1 encoding to GBK,,, if you are not, I believe also almost follow this writing step. ① first into the MySQL installation directory, notepad open My.ini file will default-character-set=latin1 Change to Default-character-set=Gbkdefault-character-set=latin1 Change to Default-character-set=GBK Note There are two lines ② but it is not enough to modify these two lines, because your database encoding is still latin1, you can doc into the MySQL command, run show variables like'character%'; the displayed content is:+--------------------------+-----------------------------------+| variable_name | Value |+--------------------------+-----------------------------------+| character_set_client | GBK | | character_set_connection | GBK | | Character_set_database | Latin1 |//The database shown here is still latin1 encoded| Character_set_filesystem | binary | | Character_set_results | GBK | | Character_set_server | GBK | | Character_set_system | UTF8 |//here is the system default| Character_sets_dir | E:\phpStudy\MySQL\share\charsets\ |+--------------------------+-----------------------------------+③ There are two ways to modify the default encoding1"When creating a database, specify the character set CREATE DATABASE Yourdb CHARACTER set GBK; If the MySQL database is encoded incorrectly: You can execute the following command in MySQL: ALTER database ' Test ' defaul T CHARACTER Set GBK COLLATE gbk_chinese_ci modify MySQL table encoding: ALTER table ' category ' DEFAULT CHARACTER SET gbk COLLATE gbk_chines E_ci Modifying a field's encoding: ALTER TABLE ' test ' change 'DD' VARCHAR ( $) CHARACTER SET gbk COLLATE gbk_chinese_ci not NULL2"I use this method because I have a PHP environment configured on my computer so I can use this method: that is, run a PHP file with the modified data encoding. You can modify the file http by filling in some data when you browse the file via the Web page://DL.VMALL.COM/C08GE26AOP files directly to the PHP file directory via the browser to open the lineby the above steps, it will be possible to show the following content in the Run command show variables like'character%'; +--------------------------+-----------------------------------+| variable_name | Value |+--------------------------+-----------------------------------+| character_set_client | GBK | | character_set_connection | GBK | | Character_set_database | GBK | | Character_set_filesystem | binary | | Character_set_results | GBK | | Character_set_server | GBK | | Character_set_system | UTF8 | | Character_sets_dir | E:\phpStudy\MySQL\share\charsets\ |+--------------------------+-----------------------------------+④ if still not ... Thought I was trying to come all the way, so there are some steps that I think may not work, but it may have worked.1"Mysql>set names GBK; Query OK,0Rows Affected (0.00sec) It corresponds to the following three-sentence instruction: SET character_set_client=GBK; SET Character_set_results=GBK; SET character_set_connection=GBK; Therefore, this method can also solve all the character encoding set to GBK, and the console display Chinese garbled problem. ⑤ Of course you can also try set character_set_client= GBK; Set this command to modify the individual variables, but I did not know this, and did not try. You can try this if you don't have the method above.
The second article:
Original address: http://www.cr173.com/html/50452_1.html
MySQL's default encoding is Latin, I each time the JSP production page inserts the database with the INSERT statement, Chinese characters will be displayed as a question mark, after installing MySQL, start the service and login, use the show variables command to view the MySQL database default encoding:
The Latin1 encoding is used by the Visual database and the server's character set, which is not supported in Chinese, which is garbled when storing Chinese. The following is a process that the command line modifies to utf-8 encoding to support Chinese.
Modified under Linux:
(1) Turn off MySQL service
[Plain] view plaincopy
Service MySQL Stop
(2) Modify the/ETC/MYSQL/MY.CNF (default installation path)
[Plain] view plaincopy
Vim/etc/mysql/my.cnf
After opening my.cnf, add the following two lines of settings under [mysqld] within the file:
[Plain] view plaincopy
Character_set_server=utf8
init_connect= ' SET NAMES UTF8 ' (pro-test, do not add also does not matter)
(as shown):
Save exit.
(3) Restart MySQL service
[Plain] view plaincopy
Service MySQL Start
At this point, complete the modification of the default encoding and re-use show variable like '%character% ' after logging into MySQL to get the following output:
Note
The specific operation and output are as follows:
Modifications under Windows:
Workaround: Open the MySQL installation directory: C:\Program files\mysql\mysql Server 5.5
Open the file My.ini configuration file, locate Default-character-set=latin1, and change to:
DEFAULT-CHARACTER-SET=GBK, find character-set-server=latin1 and change to:
CHARACTER-SET-SERVER=GBK, save after modification.
Finally: My Computer right-click on "Manage" to enter and select "Services" under "services and Applications"
After you find "MySQL", right-click to select "Restart".
Change the JSP page <%@ page language= "java" import= "java.util.*" pageencoding= "Iso-8859-1"%> to <%@ page language= "Java" Import= "java.util.*" pageencoding= "UTF-8"%> can be
Mysql character Resolution:
1, install select UTF8 encoding
2, use show VARIABLES like ' character_set_% ';
Show:
character_set_client | Latin1
character_set_connection | Latin1
Character_set_database | Latin1
Character_set_filesystem | Binary
Character_set_results | Latin1
Character_set_server | Latin1
Character_set_system | Utf8
Modify the Default-character-set under [mysqld] in My.ini to UTF8
Show
| character_set_client | Latin1
| character_set_connection | Latin1
| Character_set_database | Utf8
| Character_set_filesystem | Binary
| Character_set_results | Latin1
| Character_set_server | Utf8
| Character_set_system | Utf8
Description This setting the default character set that would be used when a new schema or table is
# created and no character set is defined (character set used by a library in the database server, if not specified when building the library, the character set specified when the server installation is used.) )
But the link character set for the server and client is still not modified
Modify [Mysql]default-character-set=utf8
Show:
| character_set_client | Utf8
| character_set_connection | Utf8
| Character_set_database | Utf8
| Character_set_filesystem | Binary
| Character_set_results | Utf8
| Character_set_server | Utf8
| Character_set_system | Utf8
Both the client and the server are unified OK
2: Modify the character encoding of your database: Enter MySQL database, modify your database character encoding by command: ALTER database ' databaseName ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_ GENERAL_CI (need to restart MySQL database after modification)
3: If your tables and table fields use incorrect character encoding, the same needs to be fixed: command:
Modify table Encoding: ALTER table ' tableName ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci
Modify the encoding of the field: ALTER TABLE ' tableName ' change ' dd ', ' DD ' VARCHAR (CHARACTER) SET UTF8 COLLATE utf8_general_ci not NULL
The main introduction of MySQL encoding for the UTF8 Setup method:
First, edit the MySQL configuration file
Vim/etc/my.cnf
Add three lines under the [Mysqld] tab
Default-character-set = UTF8
Character_set_server = UTF8
Add a line under the [MySQL] tab
Default-character-set = UTF8
Add a line under the [Mysql.server] tab
Default-character-set = UTF8
Add a line under the [Mysqld_safe] tab
Default-character-set = UTF8
Add a line to the [Client] tab
Default-character-set = UTF8
Second, restart the MySQL service can
Third, view the MySQL character set (by default, MySQL's character set is Latin1)
1. After starting MySQL, log in as root for MySQL
2. Enter the command
Show variables like ' character% ';
How to change Character_set_database latin1 to GBK (go)