MySQL Database garbled solution method
A principle of solving garbled problems: Access systems use consistent coding rules.
Use MySQL's native command line more, so you can do more things.
?
The first step:
Identify the encoding your application needs to use
Java's default encoding is to follow the system, some of which are default Unicode, and you can use String Defaultcharsetname=charset.defaultcharset () in Java. displayName (); Display encoding.
Step Two:
Confirm and set the encoding of the MySQL database
1. Display coding, simple Method command is: status; or mysql> SHOW VARIABLES like ' character% ';
mysql> status
--------------
C:\Program Files (x86) \mysql\mysql Server 5.0\bin\mysql.exe Ver 14.12 distrib 5
.0.67, for Win32 (IA32)
Connection Id:3
Current database:
Current User: [email protected]
Ssl:not in use
Using delimiter:;
Server version:5.0.67-community-nt MySQL Community Edition (GPL)
Protocol version:10
Connection:localhost via TCP/IP
Server CHARACTERSET:GBK
Db CHARACTERSET:GBK
Client CHARACTERSET:GBK
Conn. Characterset:gbk
TCP port:3306
Uptime:12 min-Sec
Threads:3 questions:32 Slow queries:0 opens:32 Flush tables:1 Open tab
Les:26 Queries per second avg:0.041
--------------
2. Modify the Encoding
Make sure that all is set to the required characters, here we take UTF8 as an example.
2.1 The changes in the My.ini configuration file (which is invalidated after the restart service using Set settings on the command line), the following changes are required for each label:
C:\Program Files (x86) \mysql\mysql Server 5.0\my.ini
[Client]
Default-character-set=utf8
[MySQL]
Default-character-set=utf8
[Mysqld]
Default-character-set=utf8
2.2 Server CharacterSet is not able to be modified in the configuration file, but also do not have to reinstall the database, only need to restart the configuration program MySQLInstanceConfig.exe.
C:\Program Files (x86) \mysql\mysql Server 5.0\bin\mysqlinstanceconfig.exe
Choose UTF8 where you choose the code, and the default is Latin1. Selected two or third, the second default is UTF8, the third hand-selected UTF8.
Step Three:
Restart MySQL Service
CMD under:
net stop MySQL
net start MySQL
mysql> use qba_db;
Database changed
mysql> status;
--------------
C:\Program Files (x86) \mysql\mysql Server 5.0\bin\mysql.exe Ver 14.12 distrib 5
.0.67, for Win32 (IA32)
Connection id:168
Current database:qba_db
Current User: [email protected]
Ssl:not in use
Using delimiter:;
Server version:5.0.67-community-nt MySQL Community Edition (GPL)
Protocol version:10
Connection:localhost via TCP/IP
Server Characterset:utf8
Db Characterset:utf8
Client Characterset:utf8
Conn. Characterset:utf8
TCP port:3306
Uptime:20 Days Hours 4 min sec
Threads:5 questions:3224 Slow queries:0 opens:151 Flush tables:1 Open
tables:0 Queries per second avg:0.002
--------------
MySQL Database garbled solution method