简析mysql字符集导致恢复生机数据库报错难题

mysql字符集编码错误的导入数据会提醒错误了,这几个和插入数据壹致只要保留的数码与mysql编码分化等那么早晚上的集会并发导入乱码或插队数据丢失的主题材料,上面大家壹块来看三个例子。

简析mysql字符集导致苏醒数据库报错难题,mysql字符集

mysql字符集编码错误的导入数据会提醒错误了,这一个和插入数据一致只要保留的数据与mysql编码不相同那么一定会出现导入乱码或插队数据丢失的难点,上边我们一道来看二个事例。

<script>ec(2);</script>

过来数据库报错:由于字符集难点,最原始的数据库暗许编码是latin一,新备份的数据库的编码是utf八,由此导致苏醒错误。

[[email protected] 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 ''<a href=\"ht' at line 1

修复方法(未实地测量):

[[email protected] ~]# /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 @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @[email protected]@TIME_ZONE */;
/*!40103 SET TIME_ZONE=' 00:00' */;
/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @[email protected]@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 */;
0
1
[[email protected] 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 @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @[email protected]@TIME_ZONE */;
/*!40103 SET TIME_ZONE=' 00:00' */;
/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @[email protected]@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 */;

字符集相关:

MySQL

mysql>show variables like '%character_set%';
-------------------------- ---------------------------- 
| Variable_name      | Value           |
-------------------------- ---------------------------- 
| character_set_client   | utf8            |
| character_set_connection | utf8            |
| character_set_database  | utf8            |
| character_set_filesystem | binary           |
| character_set_results  | utf8            |
| character_set_server   | latin1           |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
mysql>set names gbk;
mysql>show variables like '%character_set%';
-------------------------- ---------------------------- 
| 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   | latin1           |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
mysql>system cat /etc/my.cnf | grep default  #客户端设置字符集client下面 
default-character-set=gbk
mysql>show variables like '%character_set%';
-------------------------- ---------------------------- 
| Variable_name      | Value           |
-------------------------- ---------------------------- 
| character_set_client   | gbk            |
| character_set_connection | gbk            |
| character_set_database  | latin1           |
| character_set_filesystem | binary           |
| character_set_results  | gbk            |
| character_set_server   | latin1           |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
mysql> system cat /etc/my.cnf|grep character-set-server  #客户端设置字符集mysqld下面 
character-set-server = cp1250 
mysql> show variables like '%character_set%';
-------------------------- -------------------------------------------- 
| Variable_name      | Value                   |
-------------------------- -------------------------------------------- 
| character_set_client   | utf8                    |
| character_set_connection | utf8                    |
| character_set_database  | cp1250                   |
| character_set_filesystem | binary                   |
| character_set_results  | utf8                    |
| character_set_server   | cp1250                   |
| character_set_system   | utf8                    |
| character_sets_dir    | /byrd/service/mysql/5.6.26/share/charsets/ |
-------------------------- -------------------------------------------- 
8 rows in set (0.00 sec)

别的的一些装置方法:

修改数据库的字符集

  mysql>use mydb
  mysql>alter database mydb character set utf-8;

制造数据库钦命数据库的字符集

  mysql>create database mydb character set utf-8;

经过配备文件修改:

修改/var/lib/mysql/mydb/db.opt

default-character-set=latin1
default-collation=latin1_swedish_ci

default-character-set=utf8
default-collation=utf8_general_ci

重起MySQL:

[[email protected]
~]# /etc/rc.d/init.d/mysql restart

因而MySQL命令行修改:

mysql> set character_set_client=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_system=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> set collation_connection=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> set collation_database=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> set collation_server=utf8;
Query OK, 0 rows affected (0.01 sec)

查看:

mysql> show variables like 'character_set_%';
-------------------------- ---------------------------- 
| Variable_name       | Value            |
-------------------------- ---------------------------- 
| character_set_client   | utf8            |
| character_set_connection | utf8            |
| character_set_database  | utf8            |
| character_set_filesystem | binary           |
| character_set_results   | utf8            |
| character_set_server   | utf8            |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
8 rows in set (0.03 sec)
mysql> show variables like 'collation_%';
---------------------- ----------------- 
| Variable_name     | Value      |
---------------------- ----------------- 
| collation_connection | utf8_general_ci |
| collation_database  | utf8_general_ci |
| collation_server   | utf8_general_ci |
---------------------- ----------------- 
3 rows in set (0.04 sec)

总结

如上就是本文关于简析mysql字符集导致复苏数据库报错难题的全体内容,希望对我们享有匡助。有怎样难点得以每一日留言,笔者会及时回复我们。多谢朋友们对本站的支撑!

http://www.bkjia.com/Mysql/1230804.htmlwww.bkjia.comtruehttp://www.bkjia.com/Mysql/1230804.htmlTechArticle简析mysql字符集导致恢复数据库报错问题,mysql字符集
mysql字符集编码错误的导入数据会提醒错误了,那几个和插入数据壹致只要保留的数量与…

<script>ec(2);</script>

重整旗鼓数据库报错:由于字符集难点,最原始的数据库暗中同意编码是latin一,新备份的数据库的编码是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 ''<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 */;
0
1
[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 */;

字符集相关:

MySQL

mysql>show variables like '%character_set%';
-------------------------- ---------------------------- 
| Variable_name      | Value           |
-------------------------- ---------------------------- 
| character_set_client   | utf8            |
| character_set_connection | utf8            |
| character_set_database  | utf8            |
| character_set_filesystem | binary           |
| character_set_results  | utf8            |
| character_set_server   | latin1           |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
mysql>set names gbk;
mysql>show variables like '%character_set%';
-------------------------- ---------------------------- 
| 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   | latin1           |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
mysql>system cat /etc/my.cnf | grep default  #客户端设置字符集client下面 
default-character-set=gbk
mysql>show variables like '%character_set%';
-------------------------- ---------------------------- 
| Variable_name      | Value           |
-------------------------- ---------------------------- 
| character_set_client   | gbk            |
| character_set_connection | gbk            |
| character_set_database  | latin1           |
| character_set_filesystem | binary           |
| character_set_results  | gbk            |
| character_set_server   | latin1           |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
mysql> system cat /etc/my.cnf|grep character-set-server  #客户端设置字符集mysqld下面 
character-set-server = cp1250 
mysql> show variables like '%character_set%';
-------------------------- -------------------------------------------- 
| Variable_name      | Value                   |
-------------------------- -------------------------------------------- 
| character_set_client   | utf8                    |
| character_set_connection | utf8                    |
| character_set_database  | cp1250                   |
| character_set_filesystem | binary                   |
| character_set_results  | utf8                    |
| character_set_server   | cp1250                   |
| character_set_system   | utf8                    |
| character_sets_dir    | /byrd/service/mysql/5.6.26/share/charsets/ |
-------------------------- -------------------------------------------- 
8 rows in set (0.00 sec)

其它的一些安装方法:

修改数据库的字符集

  mysql>use mydb
  mysql>alter database mydb character set utf-8;

开创数据库内定数据库的字符集

  mysql>create database mydb character set utf-8;

经过铺排文件修改:

修改/var/lib/mysql/mydb/db.opt

default-character-set=latin1
default-collation=latin1_swedish_ci

default-character-set=utf8
default-collation=utf8_general_ci

重起MySQL:

[root@bogon ~]# /etc/rc.d/init.d/mysql restart

由此MySQL命令行修改:

mysql> set character_set_client=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_connection=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_database=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_results=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_server=utf8;
Query OK, 0 rows affected (0.00 sec)
mysql> set character_set_system=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> set collation_connection=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> set collation_database=utf8;
Query OK, 0 rows affected (0.01 sec)
mysql> set collation_server=utf8;
Query OK, 0 rows affected (0.01 sec)

查看:

mysql> show variables like 'character_set_%';
-------------------------- ---------------------------- 
| Variable_name       | Value            |
-------------------------- ---------------------------- 
| character_set_client   | utf8            |
| character_set_connection | utf8            |
| character_set_database  | utf8            |
| character_set_filesystem | binary           |
| character_set_results   | utf8            |
| character_set_server   | utf8            |
| character_set_system   | utf8            |
| character_sets_dir    | /usr/share/mysql/charsets/ |
-------------------------- ---------------------------- 
8 rows in set (0.03 sec)
mysql> show variables like 'collation_%';
---------------------- ----------------- 
| Variable_name     | Value      |
---------------------- ----------------- 
| collation_connection | utf8_general_ci |
| collation_database  | utf8_general_ci |
| collation_server   | utf8_general_ci |
---------------------- ----------------- 
3 rows in set (0.04 sec)

总结

以上便是本文关于简析mysql字符集导致复苏数据库报错难点的全体内容,希望对大家有所援救。有什么难点得以每四日留言,作者会及时回复大家。多谢朋友们对本站的支撑!

您也许感兴趣的篇章:

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图