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.