MySQL encoding setup method MySQL encoding for UTF8 setting method

Source: Internet
Author: User

MySQL's defaultCodingis Latin, I use the INSERT statement every time the JSP production page insertsDatabasewhen the Chinese characters are displayed as question marks, after installing MySQL, start the service and log in, use the show variables command to viewMySQL DatabaseThe 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.

(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 '

(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:

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% ';

MySQL encoding setup method MySQL encoding for UTF8 setting method

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.