想玩点东西,网上找点数据,导入数据库:
String word = "MEMBER_NO,FFP_DATE,FIRST_FLIGHT_DATE,GENDER,FFP_TIER,WORK_CITY,WORK_PROVINCE,WORK_COUNTRY,AGE,LOAD_TIME,FLIGHT_COUNT,BP_SUM,EP_SUM_YR_1,EP_SUM_YR_2,SUM_YR_1,SUM_YR_2,SEG_KM_SUM,WEIGHTED_SEG_KM,LAST_FLIGHT_DATE,AVG_FLIGHT_COUNT,AVG_BP_SUM,BEGIN_TO_FIRST,LAST_TO_END,AVG_INTERVAL,MAX_INTERVAL,ADD_POINTS_SUM_YR_1,ADD_POINTS_SUM_YR_2,EXCHANGE_COUNT,avg_discount,P1Y_Flight_Count,L1Y_Flight_Count,P1Y_BP_SUM,L1Y_BP_SUM,EP_SUM,ADD_Point_SUM,Eli_Add_Point_Sum,L1Y_ELi_Add_Points,Points_Sum,L1Y_Points_Sum,Ration_L1Y_Flight_Count,Ration_P1Y_Flight_Count,Ration_P1Y_BPS,Ration_L1Y_BPS,Point_NotFlight";
String[] list = word.split(",");
StringBuffer sql = new StringBuffer();
sql.append("create table airtab ( ");
final int flag = 0;
Arrays.asList(list).stream().distinct().filter(s -> s.trim() != null).map(x -> {
sql.append(x + "varchar(50),");
return x;
}).collect(Collectors.joining());
sql.deleteCharAt(sql.length() - 1).append(");");
System.out.println(sql.toString());
第一次导入是乱码,难受啊,看一下数据库编码my.ini:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
# 设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=C:\Users\mztt\mysql\mysql57
# 设置mysql数据库的数据的存放目录
datadir=C:\Users\mztt\mysql\mysql57\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
忽然想起我设置了,那就是csv有问题,转一下吧。
查看下数据库版本:
C:\Users\mztt\mysql\mysql57\bin>mysql --version
mysql Ver 14.14 Distrib 5.7.25, for Win64 (x86_64)
Mysql 5.7 导入数据:
mysql> load data local infile 'C:/Users/mztt/Downloads/air_data.csv'
-> into table airtab character set utf8
-> fields terminated by ',' optionally enclosed by '"' escaped by '"'
-> lines terminated by '\r\n';
Query OK, 62989 rows affected, 43 warnings (0.62 sec)
Records: 62989 Deleted: 0 Skipped: 0 Warnings: 43
ok;