MySQL encoded that little thing

Source: Internet
Author: User

Mysql Encoding Problem

In the php page You can insert English characters into MySQL , but it is not possible to insert Chinese characters, in the cmd client can also be inserted from, this is a problem that bothers me for two days.

Find a lot of information on the Internet, finally determined that the character encoding this place has a problem, first of all, to the MySQL database through the PHP page to insert Chinese characters, you have to file encoding, code encoding and MySQL encoding is consistent, my current encoding is Utf-8 , the default encoding for the file is set to Utf-8 after that, you will also be in each PHP The page is prefixed with the header ("Content-type:text/html;charset=utf-8"), mysql_query ("Set names UTF8").

Next isMySQLencoding problem, but also to set the encoding toUtf-8, my version isWin7of the -bit ofmysql5.6Installation-free version, inMysql.iniof the[Mysqld]added incharacter_set_server = UTF8, never addDefault-character-set=utf-8, because it will lead to yourMySQLcannot be opened and then passedShow variables like'%char% ' to view the encoded settings,

Character_set_client,character_set_connection,character_set_database and character_set_results are all utf-8 , basically no problem.

But in order to avoid problems, we try to set up the database and the table when it is encoded, create theexists databasename default charset UTF8; and the CREATE table if not EXISTS table TableName (col type) default CharSet UTF8; Of course we can also modify his default code, modify the database encoding ALTER DATABASE databasename default CharSet UTF8; Modifying the encoding of a table ALTER TABLE tablename default CharSet UTF8, This basically does not appear can not insert Chinese characters, or inserted in the language after the display garbled.

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.