PHP + MySQL + Apache UTF-8 character set

Source: Internet
Author: User
  • PHP sets UTF-8

PHP. ini default_charset = "UTF-8"

Header ('content-type: text/html; charset: UTF-8 ');

  • Apache sets UTF-8

<

Virtualhost

*: 80>

DocumentRoot "/var/www/html /"

Servername 111.com.tw

Adddefacharcharset UTF-8

<

Directory

"/Var/www/html/">

  • MySQL

This part is reproduced and hereby declares


MySQL Character Set Problems


MySQL character set support has two aspects:

Character Set and collation ).


The support for character sets is refined to four layers:

Server, database, table, and connection ).


1. Default MySQL Character Set


MySQL can refine the character set designation to a database, a table, and a column.


However, traditional programs do not use such complex configurations when creating databases and data tables. They use the default configuration. So where does the default configuration come from?

(1) When compiling MySQL, a default character set is specified, which is Latin1;

(2) When installing MySQL, you can specify a default character set in the configuration file (My. conf). If this character set is not specified, this value inherits from the one specified during compilation;

(3) When mysqld is started, you can specify a default character set in the command line parameters. If not, this value inherits from the configuration in the configuration file, character_set_server is set to the default character set;

(4) When creating a new database, unless explicitly specified, the character set of this database is set to character_set_server by default;

(5) When a database is selected, character_set_database is set to the default Character Set of the database;

(6) When creating a table in the database, the default Character Set of the table is set to character_set_database, which is the default Character Set of the database;

(7) When setting a column in a table, unless explicitly specified, the default character set in this column is the default Character Set of the table;

How to modify the MySQL character set:

  1. Modify the/etc/My. conf file

[Mysqld]

Default-character-set = utf8

Default-collation = utf8_general_ci

Character-set-Server = utf8

Collation-Server = utf8_general_ci

Init-connect = 'set names utf8'

[Client]

Default-character-set = utf8

The red part is the newly added content.

Restart service mysqld restart



2. method 1 modification is invalid for an existing table



Alter table review convert to Character Set utf8; test the validity of an existing table in MySQL database

 

How to view the MySQL Character Set

 

Show variables like 'collation % ';

Show variables like 'character % ';

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.