mysql字符集編碼錯誤的導入數據會提示錯誤了,這個和插入數據一樣如果保存的數據與mysql編碼不一樣那么肯定會出現導入亂碼或插入數據丟失的問題,下面我們一起來看一個例子。
<script>ec(2);</script>
恢復數據庫報錯:由于字符集問題,最原始的數據庫默認編碼是latin1,新備份的數據庫的編碼是utf8,因此導致恢復錯誤。
| [root@hk byrd]# /usr/local/mysql/bin/mysql -uroot -p'admin' t4x < /tmp/11x-B-2014-06-18.sql ERROR 1064 (42000) at line 292: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''[caption id=/"attachment_271/" align=/"aligncenter/" width=/"300/"]<a href=/"ht' at line 1 |
修復方法(未實測):
| [root@Test ~]# /usr/local/mysql/bin/mysql -uroot -p'admin' --default-character-set=latin1 t4x < /tmp/11x-B-2014-06-18.sql MySQL-- MySQL dump 10.13 Distrib 5.5.37, for Linux (x86_64)---- Host: localhost Database: t4x-- -------------------------------------------------------- Server version 5.5.37-log/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;/*!40103 SET TIME_ZONE=' 00:00' */;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;---- Current Database: `t4x`--CREATE DATABASE /*!32312 IF NOT EXISTS*/ `t4x` /*!40100 DEFAULT CHARACTER SET utf8 */;---- Table structure for table `wp_baidusubmit_sitemap`--DROP TABLE IF EXISTS `wp_baidusubmit_sitemap`;/*!40101 SET @saved_cs_client = @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATE TABLE `wp_baidusubmit_sitemap` ( `sid` int(11) NOT NULL AUTO_INCREMENT, `url` varchar(255) NOT NULL DEFAULT '', `type` tinyint(4) NOT NULL, `create_time` int(10) NOT NULL DEFAULT '0', `start` int(11) DEFAULT '0', `end` int(11) DEFAULT '0', `item_count` int(10) unsigned DEFAULT '0', `file_size` int(10) unsigned DEFAULT '0', `lost_time` int(10) unsigned DEFAULT '0', PRIMARY KEY (`sid`), KEY `start` (`start`), KEY `end` (`end`)) ENGINE=MyISAM AUTO_INCREMENT=84 DEFAULT CHARSET=utf8;/*!40101 SET character_set_client = @saved_cs_client */;01[root@hk byrd]# /usr/local/mysql/bin/mysql -uroot -p'admin' t4x < /tmp/t4x-B-2014-06-17.sql ERROR 1064 (42000) at line 295: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''i' at line 1 |
MySQL
| -- MySQL dump 10.11---- Host: localhost Database: t4x-- -------------------------------------------------------- Server version 5.0.95-log/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;/*!40103 SET TIME_ZONE=' 00:00' */;/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;-- -- Current Database: `t4x`--CREATE DATABASE /*!32312 IF NOT EXISTS*/ `t4x` /*!40100 DEFAULT CHARACTER SET latin1 */;USE `t4x`;---- Table structure for table `wp_baidusubmit_sitemap`--DROP TABLE IF EXISTS `wp_baidusubmit_sitemap`;/*!40101 SET @saved_cs_client = @@character_set_client */;/*!40101 SET character_set_client = utf8 */;CREATE TABLE `wp_baidusubmit_sitemap` ( `sid` int(11) NOT NULL auto_increment, `url` varchar(255) NOT NULL default '', `type` tinyint(4) NOT NULL, `create_time` int(10) NOT NULL default '0', `start` int(11) default '0', `end` int(11) default '0', `item_count` int(10) unsigned default '0', `file_size` int(10) unsigned default '0', `lost_time` int(10) unsigned default '0', PRIMARY KEY (`sid`), KEY `start` (`start`), KEY `end` (`end`)) ENGINE=MyISAM AUTO_INCREMENT=83 DEFAULT CHARSET=utf8;/*!40101 SET character_set_client = @saved_cs_client */; |