目录

Mysql常用命令

查询

时间转换查询

1
2
3
4
5
6
# 语法
select unix_timestamp('2022-03-21 14:28:30') from tb_event;
select from_unixtime(1666060280, '%Y-%m-%d %H:%i:%S') from tb_event;

# 示例
select from_unixtime(left(event_time,10)),origin_id from tb_event where alert_id="xxxx";

插入

更新

删除

数据导出

排除某些库导出所有库

1
mysql -e "show databases;" -uroot -p"Password" | grep -Ev "Database|db1|db2|test|information_schema|itoa|performance_schema|screen_show|zabbix" | xargs mysqldump -uroot -p"Password" --databases > /app/20221017/mysqldump_noitoa_noscreen_show_nozabbix.sql

排除某些表导出库

1
mysqldump -uroot -p"Password" --databases itoa126 --ignore-table=itoa126.srcb_health_score > /app/20221017/mysqldump_itoa_nohistory.sql

导出csv

1
select from_unixtime(left(event_time,10)),origin_id from tb_event where merge_key=1 order by event_time into outfile '/tmp/tb_event_20221017.csv' fields terminated by ',';