Talk about MySQL character set _ MySQL

Source: Internet
Author: User
Tags mysql tutorial
Let's talk about the MySQL character set. First of all, this article is purely my personal experience and is applicable to my common environments and projects.

Personally, we recommend that you use utf8 (HTMLThe page corresponds to UTF-8), so that your data can be smoothly migrated, because the utf8 character set is currently the most suitable character set for conversion between different character sets, although you may not be able to view it correctly on the command line toolDatabaseAnd I strongly recommend that you use utf8 as the default character set.

The following is a complete example:

1. create a database table

Mysql> create database if not exists my_db default charset utf8 COLLATE utf8_general_ci;

# Note the following sentence "COLLATE utf8_general_ci", which roughly means sorting by utf8 validation set during sorting

# The default character set of all data tables created in this database will be utf8.

Mysql> create table my_table (name varchar (20) not null default '') type = myisam default charset utf8;

# This statement creates a table. the default character set is utf8.

2. write data

Example 1: insert data directly using php:

A. php
Mysql_connect ('localhost', 'user', 'password ');
Mysql_select_db ('My _ db ');

// Note that this step is critical. without this step, all data reads and writes will be incorrect.
// It sets the default character set for data transmission during the database connection.
// Other programming languages/interfaces are similar, such as. net/c #/odbc
// For jdbc, set the connection string to "jdbc: mysql: // localhost/db? User = user & password = 123456 & useUnicode

= True & characterEncoding = UTF-8"

Mysql_query ("set names utf8 ;");
// You must convert gb2312 (locally encoded) to utf-8. you can also use the iconv () function.
Mb_convert_encoding ("insert into my_table values ('test');", "UTF-8", "gb2312 ");

B. php
// Output this page encoded as UTF-8
Header ("content-type: text/html; charset = utf-8 ");

Mysql_connect ('localhost', 'user', 'password ');
Mysql_select_db ('My _ db ');

Mysql_query ("set names utf8 ;");
If (isset (Talk about MySQL character set-webmaster College

Future Chinese webmasters will focus more on the development of China's networksAdvertisement service | latest update | add to favorites | set as Homepage

  • Homepage
  • Internet software
  • IDC products
  • Webmaster transaction
  • Project outsourcing
  • Business Information
  • Recruitment
  • Company Database
  • Webmaster Mall
  • Asset Information
  • Downlink
  • School
  • Work Tools
  • Tan

Popular keywords:For CSS layout color, see Dreamweaver8 apacheApacheIIS6AjaxWML

Homepage | HOME webmaster getting started operation planning search optimization website profit webpage design HtmlCSS/XhtmlDhtmlWAPDreamweaver design principles graphic animation photoshopFireworkFlash website development Asp. NetPhpJspMssqlAccessOracleMysql server FressbsdLINUXWindows

Video tutorial Frequently used manual Common advertisement code Js special effect code

Webmaster College> Website Development technical tutorial> mysql tutorial> Talk about MySQL character set

Introduction to MySQL character set

14:46:00 view learning experience

{GetProperty (Content )}

Related Article

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: 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.