需要注意语法: load data local inpath [local path] into table [table name]
1 2 3 4 5
hive> load data local inpath '/opt/module/datas/student.txt' into table student; Loading data to table default.student Table default.student stats: [numFiles=3, numRows=0, totalSize=66, rawDataSize=0] OK Time taken: 1.397 seconds
查看 WebUI
查询
1 2 3 4 5 6 7 8 9
hive> select * from student; OK 1 laiyy 2 laiyy1 NULL NULL NULL NULL NULL NULL NULL NULL Time taken: 0.282 seconds, Fetched: 6 row(s)
出现了四条 NULL 记录
解决办法
在建表的时候,就指定分隔符,且导入时,需要按照建表时指定的分隔符来分隔数据。
新建一张表,以 \t 分隔
注意语法:create table [table name] fow format delimited fields terminated by [terminated type]
1 2 3 4 5 6 7 8
hive> create table stu(id int, name string) row format delimited fields terminated by '\t'; OK Time taken: 0.12 seconds hive> show tables; OK stu student Time taken: 0.02 seconds, Fetched: 2 row(s)
导入数据到 stu 表,查看表数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14
hive> load data local inpath '/opt/module/datas/student.txt' into table stu; Loading data to table default.stu Table default.stu stats: [numFiles=1, totalSize=49] OK Time taken: 0.148 seconds
hive> select * from stu; OK 1001 zhangsan 1002 lisi 1003 wangwu 1004 zhaoliu Time taken: 0.041 seconds, Fetched: 4 row(s)
hive> load data inpath '/student2.txt' into table stu; Loading data to table default.stu Table default.stu stats: [numFiles=3, totalSize=121] OK Time taken: 0.132 seconds
Caused by: javax.jdo.JDOFatalDataStoreException: Unable to open a test connection to the given database. JDBC url = jdbc:derby:;databaseName=metastore_db;create=true, username = APP. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------ java.sql.SQLException: Failed to start database 'metastore_db' with class loader sun.misc.Launcher$AppClassLoader@214c265e, see the next exception for details. at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.bootDatabase(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source) at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source) at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source) at org.apache.derby.jdbc.Driver20.connect(Unknown Source)
错误原因
Hive 默认数据库是 derby,是单用户的,当有两个连接以上时就会报错。为了防止这个错误,可以把元数据信息从 derby 中改为存储在 mysql 中。
Logging initialized using configuration in jar:file:/opt/module/hive/lib/hive-common-1.2.1.jar!/hive-log4j.properties Thu Dec 26 15:18:55 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:55 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:55 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:55 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:56 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:56 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:56 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Thu Dec 26 15:18:56 CST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
hive>
执行一些测试
查询不到表,是因为 mysql 只是存储 元数据,而现在还没有在 mysql 做元数据存储的基础上创建 hive 表,所以查询不到。
1 2 3
hive> show tables; OK Time taken: 0.016 second
创建一个表,再查询
1 2 3 4 5 6 7
hive> create table test(id int); OK Time taken: 0.208 seconds hive> show tables; OK test Time taken: 0.018 seconds, Fetched: 1 row(s)