Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis on the causes of Database garbled in MySQL

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following content mainly brings you the cause analysis of MySQL database garbled. The knowledge mentioned here, which is slightly different from books, is summed up by professional and technical personnel in the process of contact with users, and has a certain value of experience sharing. I hope to bring help to the majority of readers.

The cause of garbled Code in MySQL Database

Any data in the computer is stored in binary, to store a character is to encode it, with a binary corresponding to it, this corresponding rule is the character coding. There are many kinds of coding rules, and the set of "characters" encoded by one rule is called "character set". When formulating coding standards, "set of characters" and "coding" are generally formulated at the same time. Therefore, what we usually call "character set", such as GB2312,GBK and UTF-8, not only has the meaning of "set of characters", but also contains the meaning of "coding".

GB2312 and GBK can be used for Chinese processing, which is a Chinese character set, while UTF-8 is a character set developed for every country and region in the world, and UTF-8 is a character set with variable storage length, such as the English alphabet needs only one byte of storage, which saves storage space, so the UTF-8 character set is usually used in the database.

Character setting problem of CVM system

Problems in the setting of datasheet languages

The problem of client connection language family

Solution method

Set the CHARACTER SET character set and COLLATE 'utf8_general_ci' when creating the database

Set through the DEFAULT CHARSET = character set when creating the table

The default character set can be set using the SET NAMES character set

Modify the configuration file to add the default_character_set= character set to the [mysql] paragraph

⑴ sets the character set when creating the database

CREATE DATABASE chartest CHARACTER SET 'utf8' COLLATE' utf8_general_ci'

⑵ sets the character set when creating the table

CREATE TABLE 'charatertest' (id varhsar (40)) DEFAULT CHARSET = utf8

⑶ uses SET NAMES to refer to the default character set

SET NAMES utf8

⑷ modifies the configuration file and adds it to the [mysql] section

Default_character_set=utf8

For example:

⑴ creates database, table, global database settings

[root@localhost] # mysql-u root-p123

Mysql > create database mydb default character set utf8 collate utf8_general_ci

Mysql > use mydb

Mysql > create table mydb_table (username varchar (64) NOT NULL) default charset=utf8

Mysql > set names utf8;# sets the default character set for the entire database

⑵ modify configuration file

[root@localhost ~] # vim / etc/my.cnf

[mysql] add after

Default_character_set=utf8

For the above analysis of the causes of MySQL database garbled, if you need to know more, you can continue to pay attention to the innovation of our industry, if you need to get professional answers, you can contact the pre-sale and after-sales on the official website. I hope this article can bring you some knowledge updates.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report