In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "Mysql Chinese garbled problem solution", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "Mysql Chinese garbled problem solution" bar!
The reasons for the occurrence of Chinese garbled codes in MySQL are as follows:
1.server itself setting problems, for example, still stuck in latin1
Language Family setting of 2.table (including character and collation)
3. The problem of setting the connection language of a client program (e. G.)
It is strongly recommended that you use utf8 roommates!
Utf8 can be compatible with all the characters in the world!
First, avoid creating databases and tables in Chinese garbled and viewing coding methods
1. When creating a database: CREATE DATABASE `test`
CHARACTER SET 'utf8'
COLLATE 'utf8_general_ci'
2. CREATE TABLE `database_ user` when creating the table (
`ID`varchar (40) NOT NULL default''
`UserID`UserID` varchar (40) NOT NULL default''
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Once these three are set up, there will be no problem, that is, the same coding format will be used when building the database and the table.
But if you have built libraries and tables, you can query them in the following ways.
1. View the default encoding format:
Mysql > show variables like "char%"
+-+ +
| | Variable_name | Value |
+-+ +
| | character_set_client | gbk |
| | character_set_connection | gbk |
| | character_set_database | utf8 |
| | character_set_filesystem | binary |
| | character_set_results | gbk |
| | character_set_server | utf8 |
| | character_set_system | utf8 |
+-+ +
Note: the default encoding format can be set using set names utf8,set names gbk to determine the previous 2.
The effect of executing SET NAMES utf8 is equivalent to setting the following at the same time:
SET character_set_client='utf8'
SET character_set_connection='utf8'
SET character_set_results='utf8'
two。 View the encoding format of the test database:
Mysql > show create database test
+-+ +
| | Database | Create Database |
+-+ +
| | test | CREATE DATABASE `test` / *! 40100 DEFAULT CHARACTER SET gbk * / | |
+-+ +
3. View the encoding format of the yjdb database:
Mysql > show create table yjdb
| | yjdb | CREATE TABLE `yjdb` (
`sn`int (5) NOT NULL AUTO_INCREMENT
`type` varchar (10) NOT NULL
`brc` varchar (6) NOT NULL
`teller` int (6) NOT NULL
`telname` varchar (10) NOT NULL
`date`int (10) NOT NULL
`count` int (6) NOT NULL
`back` int (10) NOT NULL
PRIMARY KEY (`sn`)
UNIQUE KEY `sn` (`sn`)
UNIQUE KEY `sn_ 2` (`sn`)
) ENGINE=MyISAM AUTO_INCREMENT=1826 DEFAULT CHARSET=gbk ROW_FORMAT=DYNAMIC |
Second, avoid the problem of garbled Chinese characters in the imported data
1: save the data encoding format as utf-8
Set the default encoding to utf8:
Set names utf8
Set the database db_ name to utf8 by default:
ALTER DATABASE `db_ name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
Set the default encoding of table tb_name to utf8:
ALTER TABLE `tb_ name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
Import:
LOAD DATA LOCAL INFILE'C:\\ utf8.txt' INTO TABLE yjdb
2: save the data encoding format as ansi (i.e. GBK or GB2312)
Set the default encoding to gbk:
Set names gbk
Set the default db_name encoding of the database to gbk:
ALTER DATABASE `db_ name` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci
Set the default encoding of table tb_name to gbk:
ALTER TABLE `tb_ name` DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci
Import:
LOAD DATA LOCAL INFILE'C:\\ gbk.txt' INTO TABLE yjdb
Note: 1.UTF8 do not import gbk,gbk do not import UTF8
two。 The display of UTF8 is not supported under
Third, solve the problem of garbled code in the web page.
Set the site code to utf-8 so that it is compatible with all the characters in the world.
If the site has been running for a long time, there is a lot of old data, can no longer change the simplified Chinese settings, then it is recommended to set the page coding to GBK, GBK and GB2312 is the difference is: GBK can display more characters than GB2312, to display simplified code of traditional characters, can only use GBK.
1. Edit / etc/my.cnf and add default_character_set=utf8 in the [] paragraph
two。 When writing Connection URL, add the? useUnicode=true&characterEncoding=utf-8 parameter
3. Add a "set names utf8" or "set names gbk" instruction to the web page code to tell MySQL to use all connection content
Utf8 or gbk
Thank you for your reading, the above is the content of "the solution to the Chinese garbled problem in Mysql". After the study of this article, I believe you have a deeper understanding of the solution to the Chinese garbled problem in Mysql, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.