Home Database Mysql Tutorial 完美转换MySQL的字符集 解决查看utf8源文件中的乱码问题

完美转换MySQL的字符集 解决查看utf8源文件中的乱码问题

Jun 07, 2016 pm 06:05 PM
Garbled characters character set

本人转换过好多数据了,也用过了好多的办法,个人感觉最好用的就是使用MySQL命令导出导入中将字符集转换过去

MySQL从4.1版本开始才提出字符集的概念,所以对于MySQL4.0及其以下的版本,他们的字符集都是Latin1的,所以有时候需要对mysql的字符集进行一下转换,MySQL版本的升级、降级,特别是升级MySQL的版本,为了不让程序继续沿用Latin1字符集之后对以后Discuz!版本升级的影响和安装SupeSite,这就需要我们进行字符集的转换!
本人转换过好多数据了,也用过了好多的办法,个人感觉最好用的就是使用MySQL命令导出导入中将字符集转换过去!
现在我将用图文并茂的方式向大家展示一下如何将MySQL字符集进行转换,由于字符集比较多,现在主要举GBK和Latin1这两种字符集之间的转换!
首先我将讲解一下如何将MySQL从GBK转换为Latin1的(如果是UTF8或者BIG5转换即将GBK换成相应的字符集即可)!这种问题常发生在MySQL从MySQL4.1及其以上版本转换为

MySQL4.1以下的版本的过程中!有的人图个方便,特别是有主机权限的,直接将MySQL的data目录下的文件拷贝过去了,这样造成的问题就是乱码问题!当然我所说的这些都要求你必

须拥有主机权限,虚拟主机用户可以在本地搭建好论坛,下载数据到你的本地,然后把数据导入到你本地的数据库,然后进行字符集的转换!
现在的步骤就是将MySQL的数据导出了,在mysql的命令提示符下(linux系统为mysql的命令目录下),输入下面导出的命令:
mysqldump -uroot -p --default-character-set=gbk --set-charset=latin1 --compatible=mysql40 --skip-opt discuz>discuz.sql
如图1(windows下)和图2(linux下)所示



这样就轻松的将数据从MySQL数据库中导出了,此时导出的文件在与mysql命令同级的目录下,即bin目录下,而且已经将MySQL字符集导出为Latin1的了!现在要做的就是将数据导

入MySQL4.0中去!
同样在4.0版本的mysql命令提示符下(linux系统为mysql的命令目录下),输入下面导入命令:
mysql -uroot -p --default-character-set=latin1 -f discuz如图3(window下)和图4(linux下)所示



这样就将字符集从GBK转为Latin1同时将MySQL从4.1以上版本的转为MySQL4.0的了!
现在讲解一下如何从Latin1字符集转换为GBK的!
由于只有MySQL4.1以上的版本才有字符集的概念,所以如果你要将MySQL4.0的字符集从Latin1转换为GBK字符集的话,必须导入到MySQL4.1以上的版本中,然后再导出!这里面就多

了一个导出为Latin1的步骤!
同样在MySQL4.0的命令提示符下,输入下面导出的命令:
mysqldump -uroot -p --default-character-set=latin1 --set-charset=latin1 --skip-opt discuz>discuz.sql
然后导入到MySQL4.1中,输入下面导入的命令:
mysql -uroot -p --default-character-set=latin1 -f discuz然后在MySQL4.1下转换字符集,分别输入下面导出和导入的命令:
mysqldump -uroot -p --default-character-set=latin1 --set-charset=gbk --skip-opt discuz>discuz.sql
mysql -uroot -p --default-character-set=gbk -f newdiscuz如果不出问题的话,那么转换就完毕了!其实整个过程还是比较简单的,只是过程看起来比较麻烦些,但是过程却是很简单明了的!
下面举出一个在导入过程中极易容易出现的问题!
在导入的时候容易出现unknown command '/'这样的错误,其实这是由于MySQL在导出的时候,它有时候给一些繁体字后面自动加上了个反斜杠造成的!解决此问题的办法就是打开

备份的sql(这里为discuz.sql),提示错误的时候会提示具体哪行出现了错误,找到那行,把反斜杠去掉就行了!其实你可以用Ultraedit这些文本处理的工具,批量的去处理这些反斜杠

!凭个人经验,有很多用户名取的比较怪,这样就容易出现反斜杠,这样只要纠正那些用户名就行了!
以上是个人在转换数据过程中的一些经验之谈,很多地方还有待大家完善!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve garbled word page numbers How to solve garbled word page numbers Jun 25, 2023 pm 03:23 PM

Solution to garbled word page numbers: 1. Open the word document and click the "File" option in the upper left corner; 2. Select the "More" option, and then click the "Options" button; 3. Select "Advanced" in the word options; 4. . Find "Show field codes instead of field values" in "Show document content", remove the check in front, and click OK to return to the home page.

How to solve Chinese garbled characters in Linux How to solve Chinese garbled characters in Linux Feb 21, 2024 am 10:48 AM

The Linux Chinese garbled problem is a common problem when using Chinese character sets and encodings. Garbled characters may be caused by incorrect file encoding settings, system locale not being installed or set, and terminal display configuration errors, etc. This article will introduce several common workarounds and provide specific code examples. 1. Check the file encoding setting. Use the file command to view the file encoding. Use the file command in the terminal to view the encoding of the file: file-ifilename. If there is "charset" in the output

What to do if linux tty has Chinese garbled characters What to do if linux tty has Chinese garbled characters Mar 16, 2023 am 09:20 AM

Solution to Chinese garbled characters in Linux tty: 1. Download the font fbterm through the "sudo apt-get install fbterm" command; 2. Execute the "sudo fbterm" command; 3. Change the font and font size to "font-names=Ubuntu Mono font- size=14” is enough.

How to solve tomcat startup garbled code How to solve tomcat startup garbled code Dec 26, 2023 pm 05:21 PM

Solutions to garbled tomcat startup: 1. Modify Tomcat's conf configuration file; 2. Modify the system language; 3. Modify the command line window encoding; 4. Check the Tomcat server configuration; 5. Check the project encoding; 6. Check the log file; 7 , try other solutions. Detailed introduction: 1. Modify Tomcat's conf configuration file, open Tomcat's conf directory, find the "logging.properties" file, etc.

How to solve the problem of Chinese garbled characters in Windows 10 How to solve the problem of Chinese garbled characters in Windows 10 Jan 16, 2024 pm 02:21 PM

In the Windows 10 system, garbled characters are common. The reason behind this is often that the operating system does not provide default support for some character sets, or there is an error in the set character set options. In order to prescribe the right medicine, we will analyze the actual operating procedures in detail below. How to solve Windows 10 garbled code 1. Open settings and find "Time and Language" 2. Then find "Language" 3. Find "Manage Language Settings" 4. Click "Change System Regional Settings" here 5. Check the box as shown and click Just make sure.

How to solve the problem of garbled characters in win11 system documents How to solve the problem of garbled characters in win11 system documents Jun 29, 2023 pm 06:29 PM

How to solve the problem of garbled text documents in win11? When many users use the win11 system, text documents are garbled and cannot be read normally. Many friends do not know how to solve this problem. In fact, this method is not difficult. Below, the editor has compiled the steps to solve the problem of garbled Windows 11 system documents. I hope it can bring you some inspiration! Steps to solve garbled Windows 11 system documents: 1. First, open the control panel of win11, enter control panel in the search box below, and click Search to enter the control panel. 2. After entering the panel, find the clock and area and click to enter, then click on the area option. 3. After entering, click on the management panel, and then click on Change system regional settings.

Editing method to solve the problem of garbled characters when opening dll files Editing method to solve the problem of garbled characters when opening dll files Jan 06, 2024 pm 07:53 PM

When many users use computers, they will find that there are many files with the suffix dll, but many users do not know how to open such files. For those who want to know, please take a look at the following details. Tutorial~How to open and edit dll files: 1. Download a software called "exescope" and download and install it. 2. Then right-click the dll file and select "Edit resources with exescope". 3. Then click "OK" in the pop-up error prompt box. 4. Then on the right panel, click the "+" sign in front of each group to view the content it contains. 5. Click on the dll file you want to view, then click "File" and select "Export". 6. Then you can

Solve the problem of garbled characters in win11 notepad Solve the problem of garbled characters in win11 notepad Jan 05, 2024 pm 03:11 PM

Some friends want to open a notepad and find that their win11 notepad is garbled and don't know what to do. In fact, we generally only need to modify the region and language. Win11 Notepad is garbled: First step, use the search function, search and open "Control Panel" Second step, click "Change date, time or number format" under Clock and Region Third step, click the "Manage" option above Card. The fourth step is to click "Change System Regional Settings" below. The fifth step is to change the current system regional settings to "Chinese (Simplified, China)" and click "OK" to save.

See all articles