MySQL CREATE database specify character set

Source: Internet
Author: User
Tags mysql create mysql create database

MySQL Specifies that the encoding is important when creating a database, many developers use the default encoding, but I use the experience, the development of the database encoding can be largely avoided into the garbled problem of the export.

The standard we follow is that the encoding of databases, tables, fields, and pages or text should be unified.
Many MySQL database Tools (except phpMyAdmin, I occasionally use, the function is slow) do not support the creation of the specified database encoding, of course, can change My.ini to solve this problem, but need to restart MySQL, but with the following statement will be more effective

Gbk:create database test2 DEFAULT CHARACTER SET GBK COLLATE gbk_chinese_ci;

Utf8:create DATABASE ' test2 ' DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci

Note: If the content is not set through the My.ini configuration file, it is only valid in the current state and is invalidated when the database service is restarted. So if you want to not garbled only modify the My.ini file, the database encoding can be created in the database when you specify UTF8, as follows:
|character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | Latin1 |
| Character_set_system | Utf8

Note This configuration | Character_set_server | Latin1 cannot be set to UTF8
There are still garbled characters when interacting.

All changes to UTF8 are made only if the UTF8 is set in the modified My.ini

-------------------------
MySQL Setup encoding command

SET character_set_client = UTF8;
SET character_set_connection = UTF8;
SET character_set_database = UTF8;
SET character_set_results = UTF8;
SET character_set_server = UTF8;

SET collation_connection = Utf8_bin;
SET collation_database = Utf8_bin;
SET collation_server = Utf8_bin;

Configuring default encoding in My.ini
Default-character-set=utf8

Connection Database Setup Encoding
Jdbc:mysql://192.168.1.1:3306/test?characterencoding=utf8


Common coding UTF-8 in Java; GBK; gb2312;iso-8859-1;
Corresponds to the encoding utf8;gbk;gb2312;latin1 in the MySQL database

MySQL CREATE database specify character set

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