MySQL自用脚本(不定期更新)
查询指定SQL的trace信息
mysql -uUSER -pPWD -hHOST -e "\ use ins_tc_prd; \ set session optimizer_trace='enabled=on'; \ set optimizer_trace_max_mem_size = 1638400; \ explain SQL; \ select * from information_schema.optimizer_trace\G;" > trace_log.log
查看表空间的使用情况
select table_name, (data_length+ index_length) /1024/1024 as total_mb, table_rows from information_schema.tables where table_schema= 'Database' ;//不写就是全部
查看MySQL数据库状态
mysqladmin -P3306 -uroot -p -h127.0.0.1 -r -i 1 extended-status |awk -F"|" "BEGIN{ count=0; }"'{ if($2 ~ /Variable_name/ && ((++count)%20 == 1)){\ print "----------|---------|--- MySQL Command Status --|----- Innodb row operation -----|-- Buffer Pool Read --";\ print "---Time---|---QPS---|select insert update delete| read inserted updated deleted| logical physical";\ }\ else if ($2 ~ /Queries/){queries=$3;}\ else if ($2 ~ /Com_select /){com_select=$3;}\ else if ($2 ~ /Com_insert /){com_insert=$3;}\ else if ($2 ~ /Com_update /){com_update=$3;}\ else if ($2 ~ /Com_delete /){com_delete=$3;}\ else if ($2 ~ /Innodb_rows_read/){innodb_rows_read=$3;}\ else if ($2 ~ /Innodb_rows_deleted/){innodb_rows_deleted=$3;}\ else if ($2 ~ /Innodb_rows_inserted/){innodb_rows_inserted=$3;}\ else if ($2 ~ /Innodb_rows_updated/){innodb_rows_updated=$3;}\ else if ($2 ~ /Innodb_buffer_pool_read_requests/){innodb_lor=$3;}\ else if ($2 ~ /Innodb_buffer_pool_reads/){innodb_phr=$3;}\ else if ($2 ~ /Uptime / && count >= 2){\ printf(" %s |%9d",strftime("%H:%M:%S"),queries);\ printf("|%6d %6d %6d %6d",com_select,com_insert,com_update,com_delete);\ printf("|%8d %6d %7d %7d",innodb_rows_read,innodb_rows_inserted,innodb_rows_updated,innodb_rows_deleted);\ printf("|%10d %11d\n",innodb_lor,innodb_phr);\ }}';
MySQL查询阻塞语句
select r.trx_id waiting_trx_id, r.trx_mysql_thread_Id waiting_thread, r.trx_query waiting_query, b.trx_id blocking_trx_id, b.trx_mysql_thread_id blocking_thread, b.trx_query blocking_query from information_schema.innodb_lock_waits w inner join information_schema.innodb_trx b on b.trx_id = w.blocking_trx_id inner join information_schema.innodb_trx r on r.trx_id = w.requesting_trx_id;
导出语句
--导出建表语句和数据 /opt/mysql/bin/mysqldump --defaults-file=/opt/mysql/my.cnf -uroot -p123456 -hlocalhost -R --single-transaction --default-character-set=utf8 dentist ds_user uas_user ds_organization > /opt/mysql/bak_dir/table.sql--dentist 数据库名称 -- ds_user uas_user ds_organization 表名称--导出建表语句 不包含数据 /opt/mysql/bin/mysqldump --defaults-file=/opt/mysql/my.cnf -uroot -p123456 -hlocalhost -R --single-transaction --default-character-set=utf8 -d dentist ds_user uas_user ds_organization > /opt/mysql/bak_dir/table.sql
查询表的数据量大小
select table_name,(data_length + index_length)/1024/1024 as table_mb,table_rows from information_schema.tables where table_schema='zabbix';也可以在系统上直接查看表对应的数据文件大小
转自
- http://blog.itpub.net/29510932/viewspace-1812475/
MySQL自用脚本(不定期更新)相关推荐
- 不定期更新,记录一些小知识
作者:东北大胖子 原文来源: https://tidb.net/blog/c6e3a445 不定期更新,记录一些小知识,欢迎指正,本帖尽量使用文字描述,相关图片尽量粘贴,方便大家搜索~ Mysql向T ...
- Liunx上训练模型的常见情况(不定期更新)
这篇博客用来记录一些Linux上后台训练机器学习模型的时候可能用到的简短的代码(不定期更新) 目录: 后台执行python训练脚本 查看训练时占用的资源 中途停止模型的训练 1.后台执行python训 ...
- mysql用一个表更新另一个表的方法
Solution 1: 修改1列(navicate可行) update student s, city c set s.city_name = c.name where s.city_code = ...
- mysql参数积累 持续更新。。。
mysql参数积累 持续更新... 以下是Mysql数据库服务器配置文件my.ini的详细配置.应用场合是InnoDB引擎,2核CPU, 32位SUSE. [client] #password = y ...
- 树莓派/linux 功能配置(含网络)不定期更新
最新的树莓派4B使用 Debian 10 Buster发行版本.一些基本的网络相关使用记录.不定期更新. 文章目录 0.网线网卡的配置 1.关闭蓝牙和wifi 2.关闭ipv6功能 3.route路由 ...
- Oracle OCP 11g 常见单词(不定期更新)
Oracle OCP 11g 常见单词(不定期更新) 数据库常见单词,不定期更新至考完ocp证(初步想法),现已收集807个单词: 最后一次更新时间为20180301. 1, ACCUMULATED ...
- 大数据思维导图锦集(原创吐血整理,不定期更新)
个人思维导图主页(原创吐血整理,不定期更新)https://mm.edrawsoft.cn/homepage.html?visited=18062886 其中涵盖了:数据仓库.Hadoop.Mysql ...
- 前端开发的基础生产力素养(后期不定期更新)
概要 本文主要涉及: nodejs版本管理工具nvm在win.*nix系统上的安装.更新.使用 npm.yarn.pnpm包管理工具的使用,换源及还原源 package.lock.json.yarn. ...
- 【代码总结-不定期更新】
[代码总结-不定期更新] 1 packagecom.runyi.share.service.information.commons.exceptions;2 3 importcom.runyi.ryp ...
最新文章
- 车牌检测识别--Towards End-to-End Car License Plates Detection and Recognition with Deep Neural Networks
- mysql 主从同步检查_MySQL主从复制一致性检测
- MinGW下静态编译、链接Qt 5.0
- 共享一PYTHON 相关应用领域的介绍资料
- 揭秘.NET Core剪裁器背后的技术
- 【C、C++】ctype.h、cctype中的isnumber()函数和isdigit()函数的区别
- CCF201703-1 分蛋糕(100分)
- Java思维导图(3)
- stm32cubeIDE下载无法打开GDB的问题
- 电子版白底寸照如何制作
- jtopo 比例尺功能
- java nio和io的区别_Java NIO和IO的区别
- Axure 下载教程
- STM32F103_study62_The punctual atoms(Clock system initialization function analysis)
- 关于TypeScript开发的6个小技巧
- matlab示波器图形导出,(最新整理)Matlab-simulink示波器图形保存
- 拼多多2020届数据分析面试题合集
- Textbox只留下边框线
- 魅族MX4安装Ubuntu Touch系统
- SpringSecurity最新版本使用总结