hive部分

------------------st建表(无分区)

create external table st.表名
 (
  week int comment '周',
  PV  int  comment '访问量',
  UV  int  comment '访问人数',
  prdt_type string comment '项目类型',
  updatetime    timestamp   comment '更新时间'
  ) comment '流量统计(周)'
 ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
 STORED AS TEXTFILE
 location '/dw/st/表名;



------------------st建表(有分区)

create external table st.tablename
 (
  year_month int comment '月',
  PV  int  comment '访问量',
  UV  int  comment '访问人数',
  prdt_type string comment '项目类型',
  updatetime    timestamp   comment '更新时间'
  ) comment '流量统计(月)'
 partitioned BY (month string COMMENT '按月分区表字段')
 ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
 STORED AS TEXTFILE
 location '/dw/st/表tablename';



-


------------------default建表

create external table default.tablename
 (
  year int comment '年',
  prjt_type string comment '业务类型',
  prdt_type string comment '项目类型',
  expr_cnt int comment '体验人数',
  new_expr_cnt int comment '新增体验用户数',
  charge_user_cnt int comment '收费用户数',
  new_charge_user_cnt int comment '新增收费用户数',
  back_user_cnt int comment '本期回流用户数',
  loss_user_cnt int comment '本期流失用户数',
  refund_user_cnt int comment '本期退费用户数',
  updatetime    timestamp   comment '更新时间'
  ) comment '用户统计'
 ROW FORMAT DELIMITED FIELDS TERMINATED BY '\001'
 STORED AS TEXTFILE
 location '/hive/default/tablename';



------------sqoop

sqoop-export   --connect jdbc:mysql://mysqlDB:3306/BI_02   --username biadmin  --password ***  --table st02_stock_flow_week --input-null-string '\\N' --input-null-non-string '\\N' --input-fields-terminated-by '\001' --export-dir /dw/st/stock_flow_week;


----------调整hive表结构

ALTER TABLE dms.slpltfrm_usr_bsc_info ADD COLUMNS (aplan_name string comment'投顾志名字');
ALTER TABLE stage.comment_info CHANGE commentcount commentcount STRING comment'评论数' AFTER articleid;




----------有partition的插数

insert overwrite table default.fs_pg_statspartition (day='20160926')

-------------删除partition

ALTER TABLE st.fs_pg_stats DROP PARTITION(day='${day}');

-----------了解表信息

desc formatted dms.fund_trans_log2;

desc extended dms.fund_trans_log2;

-------关于时间

一年前

select date_sub(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),365);


一年后

select date_add(from_unixtime(unix_timestamp(),'yyyy-MM-dd'),365);


-------查看表是否锁死

show locks st.st02_eqt_flow_contrb_stats



------查看建表语句

show create table st.st02_eqt_flow_contrb_stats


-------增加分区

hive -e "alter table  dms.rcmmnd_artcl  add partition(day=${day}) location'/dw/dms/rcmmnd_artcl/day=${day}';"


alter table dms.rcmmnd_artcl_type add IFNOT EXISTS  partition(day=${day})location '/dw/dms/rcmmnd_artcl_type/day=${day}';




------删除分区

hive -e "alter table  dms.rcmmnd_artcl  drop partition (day=${day});"



 

-----------看mapreduce过程

explain select * from dms.d_channel;




mysql部分

------------改变mysql表格的字段属性

alter table charts.stock_user_center modify column rcmmnd_stock text ;


-----------修改表的注释

alter table test1 comment '修改后标的注释'


---------修改字段的注释

alter table test1 modify column field_name int comment '修改后的字段注释'

---------------mysql建表

create table BI.表名
(
  halfyear  int comment '半年',
  PV  int  comment '访问量',
  UV  int  comment '访问人数',
  prdt_type string comment '项目类型',
  updatetime    timestamp   comment '更新时间'
 )
 ENGINE=InnoDB DEFAULT CHARSET=utf8 comment '证券部流量统计(半年)'



-------------mysql增加表格字段

alter table charts.user_center_future add total_income double after yst_income;


-------------mysql删除数据

DELETE FROM users WHERE name = 'Mike' LIMIT 6;



--------------mysql插入数据

插入一行
insert into links values('jerichen','gdsz');

插入多行

insert links (name,url) values('jerichen','gdsz'),('alone','gdgz');


-------update更新某个字段信息

UPDATE fs_flow_stats_dy SET ip='1674684' where dy='20160925' and bu='大网'


--------增加主键

ALTER TABLE charts.person_recom  ADD PRIMARY KEY (uid,cid, rec_tag, ordr)

--------删除主键

Alter table charts.person_recom drop primary key 


-----增加索引

ALTER TABLE table_name ADD INDEX index_name (column_list)


----删除索引

ALTER TABLE table_name DROP INDEX index_name


-- 在MySQL下运行完下面这个建表语句后。 如何从数据字典中,检索出这个表的字段的相关信息?



DROP TABLE IF EXISTS test_table;
 
CREATE TABLE test_table(
	Test_ID int NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT '主键(自增长)',
	Test_Key varchar(10) NOT NULL COMMENT '种类',
	Test_Value varchar(20) NOT NULL COMMENT '数值',
	Test_Type int NOT NULL COMMENT '内部类型',
	Test_BelongTo int COMMENT '从属关系'    ,
	Test_Grade int DEFAULT 1 COMMENT    '等级',
	Test_Remark varchar(50) COMMENT  '备注',
	Test_Visible bit DEFAULT 1 COMMENT  '是否可见'
)
COMMENT = '测试表';<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span>


-- 答案是:

SELECT 
	column_name AS '列名',
	data_type   AS '数据类型', 
	character_maximum_length  AS '字符长度', 
	numeric_precision AS '数字长度',	 
	numeric_scale AS '小数位数', 
	is_nullable AS '是否允许非空', 
	CASE 
		WHEN extra = 'auto_increment' THEN 1 
		ELSE 0 
    END AS '是否自增', 
	column_default  AS  '默认值', 
	column_comment  AS  '备注' 
FROM 
	Information_schema.columns 
WHERE 
	table_Name='test_table';



补充说明:http://blog.knowsky.com/259955.htm 参考文档不太给力啊,表注释和字段注释的资料不全。
1 创建表的时候写注释

create table test1
(
	field_name int comment '字段的注释'
)comment='表的注释';




2 修改表的注释



alter table test1 comment '修改后的表的注释';



3 修改字段的注释

-- 注意:字段名和字段类型照写就行
alter table test1 modify column field_name int comment '修改后的字段注释';


4 查看表注释的方法

-- 在生成的SQL语句中看
show create table test1;

-- 在元数据的表里面看
use information_schema;

select * 
from TABLES 
where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'


5 查看字段注释的方法

-- show
show full columns from test1;

-- 在元数据的表里面看
select * from COLUMNS where TABLE_SCHEMA='my_db' and TABLE_NAME='test1'



------linux 连接mysql

mysql -h 10.XX.xx u bata –p

set character_set_results=gbk;