MySQL data garbled problem inserted under Linux

Source: Internet
Author: User

Problem Description:

When doing the MySQL practice, found that the newly created database inserted in the data table of the records in Chinese garbled problem, such as:

After a multi-check, the entire block as follows:

Premise:

My own environment is to use the LAMPP under MySQL, the profile is in/OPT/LAMPP/ETC/MY.CNF; If you install MySQL yourself, the configuration files are generally/etc/my.cnf

Workaround:

1, first enter MSYQL, then use show variables like ' character% ', perform the code display, you can see as shown:

The default is that both the client and the server use Latin1, so it will be garbled.

2. Modify the/opt/lampp/etc/my.cof file

[Client]#password=Your_passwordport= 3306Socket= /Opt/Lampp/var/Mysql/Mysql.sockdefault-character-Set=Utf8//Add the statement[mysqld]User =Mysqlport=3306Socket= /Opt/Lampp/var/Mysql/Mysql.sockskip-External-Lockingkey_buffer=16mmax_allowed_packet=1mtable_open_cache=  -sort_buffer_size=512knet_buffer_length=8kread_buffer_size=256kread_rnd_buffer_size=512kmyisam_sort_buffer_size=8mcharacter_set_server=Utf8//Add the statement[MySQL]No-Auto-Rehashdefault-character-Set=Utf8//Add the statement

Add the above statements separately under Mysql,mysqld,client

Note: If you can not start the error after the change to try to change the Default-character-set=utf8 to Character_set_server=utf8; I have this problem here, so it's OK to remove the default, Default-character-set=utf8 is not used in the script.
3. Use the command drop database name to delete the database created

4. Restart MySQL service:/opt/lampp/lampp restart

5, re-create the database and table structure, insert data again to normal use, such as:

Method 2:

There's another way to modify the coded values using SQL statements, but I've tried to change the coded values by SQL statements, but after restarting the MySQL service, the values will be changed back to the original value. And even if you use SQL statements to modify the data table in the re-creation of the data will be inserted or garbled (it may be wrong to do, but I do not advocate this change)

Ways to modify using SQL statements:

1. First enter MySQL, then execute the following statement under MySQL:

SET character_set_database = UTF8;
SET character_set_server = UTF8;

2, use the command show variables like ' character% ', perform the code display, you can see as shown:

3, in the use of CREATE database test, the creation of databases, in the library to create a data table, and then insert the data to see if it is normal!

Reference Documentation:

Http://www.pc6.com/infoview/Article_63586.html

http://blog.csdn.net/mengzhengjie/article/details/50040527

MySQL data garbled problem inserted under Linux

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.