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 */; 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字符集导致恢复数据库报错问题的全部内容,希望对大家有所帮助。有什么问题可以随时留言,小编会及时回复大家。感谢朋友们对本站的支持!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]