mysql把latin1编码的中文转成gbk(或utf8)编码
很多项目在初建时由于工程师不严谨或者水平不够选用了错误的数据库编码,用latin1编码存储中文数据,随着项目复杂程度提高,会出现各种编码问题,可以说是后患无
很多项目在初建时由于工程师不严谨或者水平不够选用了错误的数据库编码,用latin1编码存储中文数据,随着项目复杂程度提高,会出现各种编码问题,可以说是后患无穷,网站空间,经过反复测试,网站空间,我总结出一个办法可以把latin1编码的数据库转换成gbk或u8编码,与大家分享
一. latin1 转 gbk
1.导出数据库
mysqldump --default-character-set=latin1 -h xxx.xxx.xxx.xxx -u xxx -P 3306 -pxxxxxxxx db_name table_name > /usr/home/wanghui3/table_name.sql
2.修改 table_name.sql
/*!40101 SET NAMES latin1 */; 改为 /*!40101 SET NAMES gbk */;
建表语句中
DEFAULT CHARSET=latin1; 改为 DEFAULT CHARSET=gbk;
注:不同版本的mysqldump可能稍有出入
3.导入数据库
mysql -uroot -pxxxxxxxx db_name
二. latin1 转 utf-8
1.第一步不变
2.转换编码
iconv -t utf-8 -f gbk -c table_name.sql > table_name_u8.sql
注意:用latin1保存中文本就是错误的,香港服务器,表中存储的是错误的latin1编码,但实际上是正确的gbk编码,所以这里输入编码应为gbk
3. 修改table_name_u8.sql,找到 latin1 都改为 utf8
4.导入数据库
mysql -uroot -pxxxxxxxx db_name
=======================================================
查看系统的字符集和排序方式的设定可以通过下面的两条命令:
mysql> SHOW VARIABLES LIKE 'character%';
mysql> SHOW VARIABLES LIKE 'collation_%';
本文出自 “上帝学编程” 博客,请务必保留此出处

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to underline on the computer When entering text on the computer, we often need to use underlines to highlight certain content or mark it. However, for some people who are not very familiar with computer input methods, typing underline can be a bit confusing. This article will introduce you to how to underline on your computer. In different computer operating systems and software, the way to enter the underscore may be slightly different. The following will introduce the common methods on Windows operating system and Mac operating system respectively. First, let’s take a look at the operation in Windows

Go language encoding analysis: UTF-8 and GBK comparison In the Go language, processing string encoding is one of the common tasks. Among them, UTF-8 and GBK are two commonly used character encoding methods. This article will conduct a detailed comparison between UTF-8 and GBK, discuss their differences and usage, and attach specific code examples. 1. Introduction to UTF-8 and GBK UTF-8: UTF-8 is a variable-length Unicode encoding method that can represent characters in almost all languages in the world. UTF-8

As a powerful programming language, Golang has high performance and concurrency capabilities, and also provides rich standard library support, including support for encoding conversion. This article will deeply explore the implementation principles of encoding conversion in Golang and analyze it with specific code examples. What is transcoding? Encoding conversion refers to the process of converting a sequence of characters from one encoding to another. In actual development, we often need to handle conversions between different encodings, such as converting UTF-8 encoded strings.

Learning dedecms encoding conversion function is not complicated. Simple code examples can help you quickly master this skill. In dedecms, the encoding conversion function is usually used to deal with problems such as Chinese garbled characters and special characters to ensure the normal operation of the system and the accuracy of data. The following will introduce in detail how to use the encoding conversion function of dedecms, allowing you to easily cope with various encoding-related needs. 1.UTF-8 to GBK In dedecms, if you need to convert UTF-8 encoded string to G

How to deal with encoding conversion issues in C++ development. During the C++ development process, we often encounter problems that require conversion between different encodings. Because there are differences between different encoding formats, you need to pay attention to some details when performing encoding conversion. This article will introduce how to deal with encoding conversion issues in C++ development. 1. Understand different encoding formats. Before dealing with encoding conversion issues, you first need to understand different encoding formats. Common encoding formats include ASCII, UTF-8, GBK, etc. ASCII is the earliest encoding format

PHP is a scripting language widely used in web development, especially server-side program development. In the Web development process, encoding issues are a very important part. To solve encoding problems, you need to master the encoding and conversion methods supported by PHP. This article will introduce the main encoding types and conversion methods supported by PHP. 1. Encoding types In the process of Web development, the commonly used encoding types are as follows: 1. ASCII encoding ASCII code is the American Standard Code for Information Interchange, which can represent 127 characters, including numbers and words.

"How to use the DedeCMS encoding conversion plug-in requires specific code examples" DedeCMS is a powerful and easy-to-use open source content management system that is widely used in various website construction. In the process of using DedeCMS, sometimes you will encounter situations where you need to encode the content, especially when dealing with multi-language websites or data involving different encodings. In order to simplify this operation, DedeCMS provides a coding conversion plug-in, which can easily convert the coding of content and improve the flexibility of the website.

With the development of globalization, exchanges between different languages and cultures have become more frequent and closer. The resulting problem is that character encodings between different languages and cultures have begun to become complex and diverse. When processing various data, we need to perform encoding conversion to ensure the correctness and consistency of the data. In the Go language, we can use MySQL to implement data encoding conversion. This article will introduce in detail how to use MySQL to implement data encoding conversion in the Go language. 1. Character encoding in Go language and MySQL
