Server database Coding format Problem Solution _mysql

Source: Internet
Author: User
Tags mysql command line

Server database encoding format problem

A recent project has two problems following deployment to the Aliyun server:

1, garbled problem.

2, Ajax PHP processing page inside the use of the Json_encode () function to return the JSON data, the data returned by the database can only be UTF8, if it is GBK JSON can not return.

The discovery is the database coding format problem, the website uses the encoding format to be UTF8, the database encoding format is tuned for UTF8, but the Character_set_server value or GBK.

To view the database encoding:

In the MySQL command line input: Showvariables like ' character% ';

So there are still garbled.

So I found a solution from the Internet:

In the MySQL command line input:set Character_set_server=utf8;

OK modification Successful! Returning the data is normal, but when the database service is turned off, the set Character_set_server is turned back to GBK.

So this method can only be solved temporarily.

Finally found a good workaround is to execute the SQL statement before executing the SQL statements:

$conn->query (' SET character_set_client = UTF8; ');
$conn->query (' SET character_set_results = UTF8; ');
$conn->query (' SET character_set_connection = UTF8; ');

This solution is not very personal feeling good, each execution of too many times, if you can modify the server database coding format best.

Thank you for reading, I hope to help you, thank you for your support for this site!

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.