MySQL supports the GBK character set

Source: Internet
Author: User

In the file my. ini or my. CNF, add
Default-character-set = GBK
########################
[Client]
Default-character-set = GBK
[Mysqld]
Default-character-set = GBK
#########################
Save the modification and log on to the client.
# Mysql-u root-P
Enter
> Status;
If:
Server characterset: GBK
DB characterset: GBK
Client characterset: GBK
Conn. characterset: GBK
The modification is successful.

2. Specify the GBK character set when creating a database table
When creating a database table, we need to specify the GBK character set.
Create a database:

Create Database dbnameDefault Character Set GBKCollate gbk_chinese_ci;
Create a data table
Create Table tablename (
Id int (10) unsigned not null auto_increment,
Name varchar (15) not null default '',
Primary Key (ID)
)Type = MyISAMDefault Character Set GBK;

After the creation, use the following in the client:
> Show create table tablename;
IfDisplay GBK in the last line, Indicates success

3. Modify the JDBC driver
JDBC driver is required for connecting JSP to MySQL. When Using JSP, we need to set the character set.
String user = "root ";
String Password = "1234 ";
String url = "JDBC: mysql: // localhost: 3306/dbname? Useunicode = true &Characterencoding = GBK"
Class. fornname ("com. MySQL. JDBC. Driver"); // load the driver class;
Connection con = drivermanager. getconnection (URL, user, password); // get the connection
Dbname is the name of your database, and GBK in the URL is the character set used.

4.php< br> must be added to the PHP file:
mysql_query (" set names 'gbk' ");
after completing the preceding three steps, MySQL can support GBK Chinese.

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.