Specify the encoding and sorting rules when creating a database in MYSQL.

Source: Internet
Author: User

It is important to specify the encoding and sorting rules when creating a database in MYSQL. Many developers use the default encoding, but from my experience, coding databases can avoid garbled characters caused by import and export. Www.2cto.com the standard we follow is that the encoding of databases, tables, fields, and pages or texts must be unified by many mysql database tools (except phpmyadmin, Which I occasionally use and is highly functional and slow) the database encoding cannot be specified during creation. You can change it to my. ini to solve this problem, but you need to restart mysql, but use the following statement to make it more effective GBK: create database 'database name' default character set gbk COLLATE gbk_chinese_ci; UTF8: create database 'test2' default character set utf8 COLLATE utf8_general_ci Note: if not through my. the content set in the ini configuration file is valid only in the current status and becomes invalid after the Database Service is restarted. So if you want to avoid garbled characters, you only need to modify my. INI file. You can specify UTF8 when creating a database, as shown in the following code: www.2cto.com | character_set_client | utf8 | character_set_connection | utf8 | character_set_database | utf8 | optional | binary | optional | utf8 | required | latin1 | utf8 pay attention to this Configuration | | latin1 cannot be set to UTF8. garbled characters still appear during interaction. Only when my. SET UTF8 in ini to UTF8 encoding mysql to SET the encoding command www.2cto.com SET character_set_client = utf8; SET character_set_connection = utf8; SET character_set_database = utf8; SET encoding = utf8; /* Note that it is useful. */SET character_set_server = utf8; SET collation_connection = utf8_bin; SET collation_database = utf8_bin; SET collation_server = utf8_bin; my. configure default-charact in ini Er-set = utf8 Connection database setup code jdbc: mysql: // 192.168.0.5: 3306/test? CharacterEncoding = utf8 /************************************ ****************************** * Common Coding UTF-8 in java; GBK; GB2312; ISO-8859-1; corresponding mysql database encoding utf8; gbk; gb2312; latin1 --------------------------- database connection string in the specified character set URL = jdbc: mysql: // yourIP/college? User = root & password = yourPassword & useUnicode = true & characterEncoding = gbk # Mysql

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.