Skip to content

Instantly share code, notes, and snippets.

@likai24
likai24 / size.sql
Last active July 22, 2016 07:17
计算表的size
SELECT
CONCAT(FORMAT(DAT/POWER(1024,pw1),2),' ',SUBSTR(units,pw1*2+1,2)) DATSIZE,
CONCAT(FORMAT(NDX/POWER(1024,pw2),2),' ',SUBSTR(units,pw2*2+1,2)) NDXSIZE,
CONCAT(FORMAT(TBL/POWER(1024,pw3),2),' ',SUBSTR(units,pw3*2+1,2)) TBLSIZE
FROM
(
SELECT DAT,NDX,TBL,IF(px>4,4,px) pw1,IF(py>4,4,py) pw2,IF(pz>4,4,pz) pw3
FROM
(
SELECT data_length DAT,index_length NDX,data_length+index_length TBL,
@likai24
likai24 / insert_load_test.sql
Created July 7, 2016 15:27
插入100w数据测试
drop table if exists optlog1;
CREATE TABLE `optlog1` (
`object` varchar(255) DEFAULT NULL,
`objectId` int(11) DEFAULT NULL,
`action` varchar(255) DEFAULT NULL,
`log` varchar(255) DEFAULT NULL,
`cabinet` varchar(255) DEFAULT NULL,
`org` int(11) DEFAULT NULL,
`uid` varchar(255) DEFAULT NULL,
@likai24
likai24 / checkdatasize.sql
Created July 7, 2016 15:26
查看表的avg大小 in byte
show table status from hi_db_schema where name = 'optlog1';
@likai24
likai24 / check_init.sh
Created June 27, 2016 17:23
检查系统的启动命令
#!/bin/bash
# from http://unix.stackexchange.com/questions/18209/detect-init-system-using-the-shell
if [[ `/sbin/init --version` =~ upstart ]]; then echo using upstart;
elif [[ `systemctl` =~ -\.mount ]]; then echo using systemd;
elif [[ -f /etc/init.d/cron && ! -h /etc/init.d/cron ]]; then echo using sysv-init;
else echo cannot tell; fi
@likai24
likai24 / get_opt.sh
Created June 26, 2016 06:04
获取参数设置
#!/bin/bash
aflag=no
bflag=no
flist=""
set -- $(getopt abf "$@")
while [ $# -gt 0 ]
do
case "$1" in
-a) echo 1;;
-b) echo 2;;
@likai24
likai24 / setup_app.sh
Created June 23, 2016 04:38
展示了接受参数的方法
#!/usr/bin/env bash
#
# @version : 0.0.1
#
#####################
# Global Configuration
set -o pipefail
set -o errexit
@likai24
likai24 / check_installed.sh
Created June 23, 2016 04:35
检查软件有没有安装
# check whether git is installed
command -v git >/dev/null 2>&1 || { echo >&2 "git is required but it's not installed. Aborting."; exit 1; }
# check node
check_node=$(which node);
if [[ -z $check_node ]];
then
# install_node
else
echo 'Node Already Installed';
@likai24
likai24 / setup_nginx.sh
Created June 23, 2016 04:31
一个使用模板脚本tpl.sh的例子
#!/usr/bin/env bash
# This file is to setup nginx for php application
# @Version : 0.0.1
# @Usage : ./setup.sh [appname] [server_name] [port] [fpm_port]
# @Example : ./setup.sh oa_attr attr.meikecheng.com 80 9023
#
set -o pipefail
set -o errexit
# set -o xtrace
@likai24
likai24 / tpl.sh
Created June 23, 2016 04:29
简单的模板脚本
#!/usr/bin/env bash
# This file is to setup nginx for php application
#
# @Version : 0.0.1
# @Usage : tpl.sh template
# can not be used to render bash script, use sed instead
#
set -o pipefail
set -o errexit
# set -o xtrace
@likai24
likai24 / help.sh
Created June 23, 2016 04:27
用来打印help的脚本
#!/usr/bin/env bash
#
# help function
#
# @version : 0.0.1
#
#
#############################################
function help () {
echo -e "\033[1m${1}\033[0m" 1>&2