Solve the Chinese garbled problem in Mac Mysql database, macmysql

Source: Internet
Author: User

Solve the Chinese garbled problem in Mac Mysql database, macmysql

MySQL database Chinese garbled solution on Mac:

When we use a framework to store databases, we often encounter Chinese garbled characters.

For example, when using the SSH framework in Java, We need to configure the encoding filter in the web. xml file. The specific code is:

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> <! -- Form processing garbled characters must be before the OpenSessionInViewFilter 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 is stored, the Chinese characters stored in the database are garbled. At this time, the debugging project finds that the final input SQL parameter value is already normal Chinese,

In this case, we need to check the database encoding.

Use SQL commands to view the default encoding format:

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> show variables like "% char %"; </span>

View the encoding format of the test database:

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> show create database test; </span>

Then we can modify the MySQL encoding in Max:

Because the default MySql character set for Mac is not UTF-8, You need to perform the following steps to modify it:

Enter

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> sudo-s </span>

Then you are prompted to enter the password, which is the system password!

Enter

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> cd/usr/local/mysql/support-files </span>

Continue input (copy the file to the etc directory)

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> cp my-default.cnf/etc/my. cnf </span>

Continue input (enter the etc directory)

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> cd/etc </span>

Continue Input

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> vimy. cnf </span>

At this time, you will find that I. the cnf file uses the h, j, k, and l buttons on the keyboard to move the cursor up, down, left, and right. The Mac system version is different!

Then press the j key to move the cursor to the end of the [client] and add an attribute: (or use the next key)

<Span style = "font-family: FangSong_GB2312; font-size: 14px;"> default-character-set = utf8 (this attribute cannot be created after mysql 5.5

Added below mysqld, that is, versions earlier than 5.5, and later versions ignore this attribute) </span>

Press the key again, move the cursor to the end of [mysqld], and add three attributes.

<span style="font-family:FangSong_GB2312;font-size:14px;">default-storage-engine=INNODB  character-set-server=utf8  collation-server=utf8_general_ci</span> 

Press the esc key in the upper left corner of the keyboard to launch the editing mode. Then, enter a colon and letter x.

Restart MySql Service

In this case, the database operation is performed again, and Chinese characters can be properly stored!

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

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.