Mac under the MySQL database Chinese garbled solution:
When we use the framework for database storage operations, we often encounter the problem of garbled Chinese.
For example, when using the SSH framework in Java, we need to configure the encoded filter in the Web.xml file, which is:
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" ><!--Form processing garbled, must be in opensessioninviewfilter filter before-->
<filter>
<filter-name> Characterfilter</filter-name>
<filter-class> org.springframework.web.filter.characterencodingfilter</filter-class>
<init-param>
< param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param >
</filter>
<filter-mapping>
<filter-name>characterfilter</filter-name >
<url-pattern>/*</url-pattern>
</filter-mapping></span>
Then when the database storage to find the database stored in Chinese or garbled, this Time debugging project found the last incoming SQL parameter value is normal Chinese,
So this time we need to look at the code of the database.
To view the default encoding format using SQL commands:
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >show variables like "%char%";</span>
To view the encoding format of the test database:
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >show CREATE DATABASE Test;</span>
And then we do the MySQL code changes under Max:
Because the Mac version of the MySQL default character set is not utf-8, the following steps are required to modify
Enter in the terminal
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >sudo-s</span>
Then prompt for the password, this password is the system password!
On the command line, enter
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >cd/usr/local/mysql/support-files</span>
Continue typing (copy file to etc directory)
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >CP my-default.cnf/etc/my.cnf</span>
Continue to enter (enter etc directory)
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >cd/etc</span>
Continue Typing
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >vimy.cnf</span>
This time, you will find the VI tool to open the MY.CNF file, its cursor up and down around the keyboard through the H, J, K, l these several keys, Mac system version is not the same 10.9.3 system cursor is the key is working!
Then press the J key to move the cursor to the end of [client] and add an attribute: (or use the next key)
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >default-character-set=utf8(this property is not available after MySQL 5.5
Mysqld is added below, which is the previous version of 5.5, and the later version ignores this property) </span>
Continue pressing the key, move the cursor after [mysqld], add 3 properties
<span style= "FONT-FAMILY:FANGSONG_GB2312;FONT-SIZE:14PX;" >default-storage-engine=innodb
Character-set-server=utf8
Press the ESC key in the upper-left corner of the keyboard to eject the edit mode and enter a colon and letter X
Restart the MySQL service
The database operation is performed again at this time, the Chinese can be stored normally!
Thank you for reading, I hope to help you, thank you for your support for this site!