MySQL命令行导入sql文件时出现乱码解决方案

时间:2022-09-20 17:44:21

Note:

sql> source F:weibo.sql(执行相关sql文件)

sql> select * from sina into outfile "/weibo.txt"(导出相应数据到C:的weibo.txt)

 

1. mysql 5.0后其客户端仅支持gbk,故可在sql> set names gbk;

例如:

set names gbk;
/*
Navicat MySQL Data Transfer

Source Server         : localhost_3306
Source Server Version : 50140
Source Host           : localhost:3306
Source Database       : sinaweibo

Target Server Type    : MYSQL
Target Server Version : 50140
File Encoding         : 65001

Date: 2013-12-16 09:16:41
*/
Create database `SinaData` DEFAULT CHARACTER SET gbk; 
use `SinaData`;
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `xinlang`
-- ----------------------------
DROP TABLE IF EXISTS `xinlang`;
CREATE TABLE `xinlang` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `person_id` varchar(255)  DEFAULT NULL,
  `article` varchar(1000)  DEFAULT NULL,
  `discuss` varchar(100) DEFAULT NULL,
  `transmit` varchar(255)  DEFAULT NULL,
  `time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
)ENGINE=MyISAM DEFAULT CHARSET=gbk;
-- ----------------------------
-- Records of weibo
-- ----------------------------
INSERT INTO `xinlang` VALUES ('1', '1646051850', '电影预言:指电影导演若干年前拍的电影中虚构的景象、语言在后来却成为了现实,网友把这样的电影内容称为电影预言。本文列举了三个电影预言事例……http://t.cn/S4K2hJ', '0', '0', '2011-11-29 13:26:24');

 2. Eclipse中在Windows->Preferences->Content Types->Text->Default encoding:gbk设定后即可显示中文乱码