一、建立數據庫mysql
CREATE DATABASE `itpv` CHARACTER SET 'gbk' COLLATE 'gbk_chinese_ci';sql
二、更改數據庫編碼數據庫
mysql> show variables like "%char%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)編碼
SET character_set_client='utf8';
SET character_set_connection='utf8';
SET character_set_results='utf8';spa
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+code
三、建立表:server
create table iptv1000w( OriginTime datetime, DayId int, TimeId int, DeviceId BINARY(16), StationId BINARY(16), ip
Action nvarchar(128), SubSystem nvarchar(128), BranchId int, RowVersion timestamp, AssetID nvarchar(300), ci
ContentId BINARY(16), TuneUrl nvarchar(1024), PlaylistUrl nvarchar(1024), IsPF bit)default charset=utf8;get
四、導入數據:mysql默認目錄是/tmp
load data infile '/tmp/IPTV/EventClientTrickState20140616to22/IPTV1000W.csv' into table iptv1000w fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n' ignore 1 lines;(Linux)
可能有的時候不能導入出問題:ERROR 29 (HY000): File '/tmp/IPTV/EventClientTrickState20140616to22/IPTV1000W.csv' not found (Errcode: 13)
把該文件的所屬用戶和所屬組都修改成mysql
該問題致使的緣由多是由於將最後權限 GRANT ALL PRIVILEGES ON *.* TO '%'@'%' IDENTIFIED BY "123" with grant option;(123爲密碼)覆蓋了以前設置的權限
進入mysql
use mysql;
select user,host from user;查看用戶及權限
delete user from user='%';
則不準用更改文件的所屬用戶和所屬組都修改成mysql,可正常導入導出數據
導出:select * from table1 into outfile '/tmp/xx.csv'
load data local infile 'E:/IPTV1000W.csv' into table iptv1000w fields terminated by ',' optionally enclosed by '"' escaped by '"' lines terminated by '\r\n' ignore 1 lines;(Win7)