sqoop导入mysql

进入mysql:
mysql -u root -p

显示数据库:
show databases;

创建数据库:
CREATE DATABASE JobData CHARACTER SET utf8 COLLATE utf8_general_ci;

使用数据库jobdata:
use JobData;

创建表TABLE t_city_count:
CREATE TABLE t_city_count(
    city varchar(30) DEFAULT NULL,
    count int(5) DEFAULT NULL 
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

创建表t_salary_dist:
CREATE TABLE t_salary_dist( 
salary varchar(30) DEFAULT NULL,  
count int(5) DEFAULT NULL  
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

创建表t_company_count:
CREATE TABLE t_company_count (  
  company varchar(30) DEFAULT NULL,  
  count int(5) DEFAULT NULL  
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

创建表t_kill_count:
CREATE TABLE t_kill_count(  
kills varchar(30) DEFAULT NULL,  
count int(5) DEFAULT NULL  
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

显示所有表
show tables;

退出mysql:
quit;


cd /export/servers/sqoop-1.4.6/bin

将hive的表t_ods_city导入到mysql中数据库JobData中的表t_city_count:
sqoop export \
--connect jdbc:mysql://hadoop1:3306/JobData?characterEncoding=UTF-8 \
--username root \
--password 123456 \
--table t_city_count \
--columns "city,count" \
--fields-terminated-by ',' \
--export-dir /user/hive/warehouse/jobdata.db/t_ods_city

将hive的表t_ods_salary导入到mysql中数据库JobData中的表t_salary_dist:
sqoop export \
--connect jdbc:mysql://hadoop1:3306/JobData?characterEncoding=UTF-8 \
--username root \
--password 123456 \
--table t_salary_dist \
--columns "salary,count" \
--fields-terminated-by ',' \
--export-dir /user/hive/warehouse/jobdata.db/t_ods_salary

将hive的表t_ods_company导入到mysql中数据库JobData中的表t_company_count:
sqoop export \
--connect jdbc:mysql://hadoop1:3306/JobData?characterEncoding=UTF-8 \
--username root \
--password 123456 \
--table t_company_count \
--columns "company,count" \
--fields-terminated-by ',' \
--export-dir /user/hive/warehouse/jobdata.db/t_ods_company

将hive的表t_ods_kill导入到mysql中数据库JobData中的表t_kill_count:
sqoop export \
--connect jdbc:mysql://hadoop1:3306/JobData?characterEncoding=UTF-8 \
--username root \
--password 123456 \
--table t_kill_count \
--columns "kills,count" \
--fields-terminated-by ',' \
--export-dir /user/hive/warehouse/jobdata.db/t_ods_kill

进入mysql
mysql -u root -p

show databases;

use JobData;

show tables;

select * from t_city_count;
或者排序显示:select * from t_city_count order by count desc;


select * from t_company_count;

......


 

你可能感兴趣的:(mysql,hive,sqoop)