易游网-易游模拟器

 找回密码
 立即注册
查看: 5303|回复: 0

[mysql] MySQL数据导入到infobright中

[复制链接]

1406

主题

1663

帖子

1万

积分

管理员

夏墨独周

Rank: 9Rank: 9Rank: 9

积分
10094

论坛元老技术达人

QQ
发表于 2020-2-22 14:20:59 | 显示全部楼层 |阅读模式
1. 在mysql中建一张表:

mysql> create table guoqing(
    ->    id int,
    ->    guo char(10),
    ->    qing char(10)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.01 sec)

2. 插入数据:

mysql> insert into guoqing(id,guo,qing) values('10000','1000','1');
Query OK, 1 row affected (0.00 sec)

3. 将数据导出csv文件:
最优通用导出语句
mysql> select * from guoqing into outfile '/tmp/guoqing.csv' fields terminated by ',' optionally enclosed by '"' lines terminated by '\n';               
Query OK, 1 row affected (0.00 sec)
其中optionally enclosed by '"'可以给导出的值加上双引号,避免值需要转义
官方关于可选fields参数
  Use the TERMINATED BY sub clause to specify the character recognized as the separator (delimiter) between values. By default, a semicolon ';' is assumed to separate values.
  Use the ENCLOSED BY sub clause to specify the character that begins and ends each string representing a text value. By default, a double quotation mark '"' is assumed to enclose each value. If the text values in the input fle do not use any enclosing characters, use the value 'NULL' in the ENCLOSED BY sub clause. Note that this is the same as using the empty string '' option in standard MySQL.
  Use the ESCAPED BY sub clause to support special characters that may be imbedded within text felds.

4. 在infobright中建一个表:
参见官方手册中支持的数据类型


mysql> create table guoqing(
    ->    id int,
    ->    guo char(10),
    ->    qing char(10)
    -> ) ENGINE=brighthouse DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.02 sec)

5. 导入csv到infobright表中:

导入前先确认字符集是否支持中文,如果不支持,设置字符集,防止中文乱码。
mysql> set names 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_database ='utf8';   
Query OK, 0 rows affected (0.00 sec)

mysql> load data infile '/tmp/guoqing.csv' into table guoqing fields terminated by ',' optionally enclosed by  '"' lines terminated by '\n';                                
Query OK, 1 row affected (0.04 sec)
Records: 1  Deleted: 0  Skipped: 0  Warnings: 0

5,验证:
mysql> select * from guoqing;
+-------+------+------+
| id    | guo  | qing |
+-------+------+------+
| 10000 | 1000 | 1    |
+-------+------+------+
1 row in set (0.00 sec)

这样mysql中的数据就能导入到infobright中了。



来源:易游模拟器(QQ:207621422),转载请注明出处!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|易游网-易游模拟器 Copyright @2015-2021 ( 浙ICP备15028007号-1 )

GMT+8, 2024-4-29 19:07 , Processed in 0.045900 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表