MySQL database table garbled Solution

Source: Internet
Author: User

The MySQL database table garbled solves the issue of specifying the encoding when creating a mysql database. Many developers use the default encoding, but from my experience, coding databases can avoid garbled characters caused by import and export. The standard we follow is that the encoding of databases, tables, fields, and pages or texts must be unified. Many mysql database tools (except phpmyadmin, Which I occasionally use, are slow in functionality) 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 the following statement will be more effective with 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 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: | bytes | utf8 | character_set_connection | utf8 | character_set_database | utf8 | bytes | binary | bytes | utf8 | bytes | latin1 | character_set_system | utf8 pay attention to this Configuration | bytes | when latin1 cannot be set to UTF8 for interaction, garbled characters still occur. Only when my. SET UTF8 in ini to UTF8 encoding mysql. 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; my. configure the default encoding default-character-set = utf8 in ini to connect to the database. set the encoding 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: create database 'database' character set 'utf8' COLLATE 'utf8 _ general_ci '; 2. when creating a TABLE, create table 'database _ user' ('id' varchar (40) not null default '', 'userid' varchar (40) not null default '',) ENGINE = InnoDB default charset = utf8; 3. when setting a URL, jdbc: mysql: // localhost/database? SeUnicode = true; characterEncoding = UTF-8 modify database default encoding alter database 'test' default character set utf8 COLLATE utf8_bin Modify TABLE encoding: alter table 'category 'default character set utf8 COLLATE utf8_bin

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.