Install my search results online
Run
Code: Sudo gedit/etc/MySQL/My. CNF
Set the default encoding to utf8.Code:[Client]
Port = 3306
Socket =/var/run/mysqld. Sock
# The default character set is utf8.
Default-character-set = utf8Code:[Mysqld]
#
# * Basic settings
#
# The default character set is utf8.
Default-character-set = utf8
Restart MySQL
But I useCode:Show variables like 'character % ';
Result Code: + -------------------------- + ---------------------------- +
| Variable_name | value |
+ -------------------------- + ---------------------------- +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | Latin1 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | utf8 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/MySQL/charsets/|
+ -------------------------- + ---------------------------- +
Where
Code: | Character_set_database | Latin1 |
Why not change
In addition, Java cannot be inserted into Chinese. Java has used utf8 to transcode Chinese.
the default character set in MySQL is Latin1,
to set the character set to uft-8, you can. add the following settings to the CNF file:
· [client]
default-character-set = utf8
· [mysqld]
default-character-set = utf8
skip-character-set-client-handshake # the character set of the client is ignored, use Server Settings
(select one from the Skip statement and the default statement in the client)
Of course, you can set the required character set when creating a database:
Create Database db_name default Character Set utf8 Callate utf8-general-ci;
You can also set: Set names 'utf8' before connecting to the database;
The emphasis is on the red text. Skip-character-set-client-handshake is added, so no default is added to the client.
Show variables like 'characte % ';
+ -------------------------- + ---------------------------- +
| Variable_name | value |
+ -------------------------- + ---------------------------- +
| 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 |
| Character_sets_dir |/usr/share/MySQL/charsets/|
+ -------------------------- + ---------------------------- +
_________________
Notes
-------------------------------------
Http://blog.163.com/wqt_1101
It is very important to specify the encoding when creating a MySQL database. Many developers use the default encoding, but from my experience, coding databases can avoid garbled characters caused by import and export.
The standard we follow is that the encoding of databases, tables, fields, and pages or texts should be unified.
Many MySQL database tools (except phpMyAdmin, which are occasionally used and feature-intensive) do not support specifying database encoding during creation. Of course, you can change it to my. INI to solve this problem, but you need to restart MySQL, but the following statement will be more effective
GBK: Create Database Test2 default Character Set GBK collate gbk_chinese_ci;
Utf8: Create Database 'test2' default Character Set utf8 collate utf8_general_ci
Note: if it is not set through the my. ini configuration file, it is only valid in the current status and will expire after the Database Service is restarted. Therefore, if you want to modify the my. ini file without garbled characters, you can specify utf8 during database creation as follows:
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | utf8 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | Latin1 |
| Character_set_system | utf8
Note This Configuration | character_set_server | Latin1 cannot be set to utf8
Garbled characters still occur during interaction.
Only when utf8 is set in my. ini will all be changed to utf8
-------------------------
MySQL encoding command
Set character_set_client = utf8;
Set character_set_connection = utf8;
Set character_set_database = utf8;
Set character_set_results = utf8;/* be sure to use it here */
Set character_set_server = utf8;
Set collation_connection = utf8_bin;
Set collation_database = utf8_bin;
Set collation_server = utf8_bin;
Configure the default encoding in my. ini
Default-character-set = utf8
Connect to the database and set the Encoding
JDBC: MySQL :/// 192.168.0.5: 3306/test? Characterencoding = utf8
/*************************************** ** Java and mysq encoding correspond ********************************* *******/
Common Coding UTF-8 in Java; GBK; gb2312; ISO-8859-1;
Corresponds to the UTF-8, GBK, gb2312, and Latin1 codes in the MySQL database.
---------------------------
Url = JDBC: mysql: // yourip/College? User = root & Password = yourpassword & useunicode = true & characterencoding = GBK
Reprinted address:
Http://forum.ubuntu.org.cn/viewtopic.php? T = 204749
http://tdcq.iteye.com/blog/363955