An error occurred while inserting Chinese characters into Ubuntu MySQL.

Source: Internet
Author: User

I am writing a small website job today. I can use jsp to insert data to MySQL in Ubuntu 8.10. Both English and numbers can be inserted, but Chinese characters won't work. I used all the jsp Chinese characters. I tried to use mysql query browser (a MySQL GUI tool) to insert Chinese data here, the result returns the incorrect string value ..... I understand the cause of this error. Then I used baidu and google to search and finally solved the problem. Now I want to share my experience as follows:

First stop MySQL service: sudo/etc/init. d/mysql stop

Then edit the MySQL configuration file sudo gedit/etc/mysql/my. cnf.

Add the following content to the [client] section of the my. cnf File

Default-character-set = utf8
[Mysqld_safe]
Default-character-set = utf8
[Mysqld]
Default-character-set = utf8
[Mysql]
Default-character-set = utf8

Restart the MySQL service,

Sudo/etc/init. d/mysql start

Enter the MySQL Command Prompt and enter the following command:

Mysql> show variables like '% char % ';

If the items in the list are the same as the following, the configuration is successful,

+ ---------------------- + ---------------------
| 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/

Then, delete the original database and create a new database (I did this, but if I did not, it would still cause errors)

Now Chinese data can be inserted

Successful

Linuxidc Disclaimer: This article only represents the author's personal opinion and has nothing to do with the help house. Its originality, as well as the statement text and content in this article have not been confirmed by this site, this article and all or part of the content, the authenticity, integrity, timeliness of this site do not make any warranty or commitment, for your reference only, please verify the relevant content on your own.

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.