mysql 一些命令

1、修复数据表
check table

repair table

2.、if and then
CASE WHEN b.if_state=1 THEN '连载中' WHEN b.if_state=2 THEN '全本' WHEN b.if_state=3 THEN '选载' WHEN b.if_state=4 THEN '首发' WHEN b.if_state=5 THEN '普通' WHEN b.if_state=6 THEN '独家' WHEN b.if_state=7 THEN '转载' ELSE "未知" END AS states

3 如果发现一个数据异常的大了,需要查看一下其中哪些表变大了,可以使用如下命令

select table_name,data_length from information_schema.tables;


4.查看整库
select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size, 
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_SCHEMA = 'databasename';


5.查看单表
select concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size, 
concat(truncate(sum(max_data_length)/1024/1024,2),'MB') as max_data_size,
concat(truncate(sum(data_free)/1024/1024,2),'MB') as data_free,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables where TABLE_NAME = 'tablename';


6.到处数据:

SELECT user_name,title INTO OUTFILE '/tmp/book_finish_title.txt'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FROM online_book where if_state = 2;


7.sql case
select b.book_id,b.title,b.user_name,b.fauthor,m.email,b.cate_name,b.total_roll,b.total_chapter,b.total_words, case b.if_state when 1 then '连载中' when 2 then '全本' when 3 then '选载' else '其他' end ,case b.if_audit when 4 then '首发 when 5 then '普通' when 6 then '独家' when 7 then '转载' else '其他' end , b.price from ecm_online_book as b left join ecm_member as m on (b.user_id = m.user_id)  where b.mes_from =1 and b.approve =1 into outfile '/tmp/book613.txt' fields terminated by '|' LINES TERMINATED BY '\r\n';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值