中国DBA联盟(ACDU)成员,目前从事DBA及程序编程(Web\java\Python)工作,主要服务于生产制造
现拥有 Oracle 11g OCP/OCM、Mysql、Oceanbase(OBCA)认证
分布式TBase\TDSQL数据库、国产达梦数据库以及红帽子认证
从业8年DBA工作,在数据库领域有丰富的经验
B站主播Oracle、Mysql、PG实战课程,请搜索:jeames007
微信:jem_db
QQ:2243967774
简介:
本文汇总了Mysql常用的运维命令,希望对于DBA们有帮助
1、 MySQL 的注释
MySQL 注释符有三种:
1、#...
2、"-- ..." (注意 -- 后面有一个空格)
3、/*...*/
2、 如何查看 MySQL 数据库的大小
查询所有数据的大小:
mysql> select concat(round(sum(data_length/1024/1024),2),'MB') as data from information_schema.tables;
查看指定数据库的大小,例如查看数据库db_school 的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data
from information_schema.tables where table_schema='db_school';
查看指定数据库的某个表的大小,例如查看数据库db_school 中 db_school表的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data
from information_schema.tables
where table_schema='db_school' and table_name='db_school';
当前数据库实例的所有数据库及其容量大小:
select a.SCHEMA_NAME, a.DEFAULT_CHARACTER_SET_NAME,a.DEFAULT_COLLATION_NAME,
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)',
sum(truncate((data_length+index_length)/1024/1024, 2)) as '总大小(MB)',
sum(truncate(max_data_length/1024/1024, 2)) as '最大值(MB)',
sum(truncate(data_free/1024/1024, 2)) as '空闲空间(MB)'
from INFORMATION_SCHEMA.SCHEMATA a
left outer join information_schema.tables b
on a.SCHEMA_NAME=b.TABLE_SCHEMA
group by a.SCHEMA_NAME, a.DEFAULT_CHARACTER_SET_NAME,a.DEFAULT_COLLATION_NAME
order by sum(data_length) desc, sum(index_length) desc;
占用空间最大的前 10 张表
SELECT
table_schema AS '数据库',
table_name AS '表名',
a.TABLE_TYPE,
a.`ENGINE`,
a.CREATE_TIME,
a.UPDATE_TIME,
a.TABLE_COLLATION,
table_rows AS '记录数',
TRUNCATE ( data_length / 1024 / 1024, 2 ) AS '数据容量(MB)',
TRUNCATE ( index_length / 1024 / 1024, 2 ) AS '索引容量(MB)',
TRUNCATE ( ( data_length + index_length ) / 1024 / 1024, 2 ) AS '总大小(MB)'
FROM information_schema.TABLES a
ORDER BY ( data_length + index_length ) DESC
LIMIT 10;
3.如何查看MySQL的版本?
有如下几种办法:
① mysql -V
② mysql> show variables like '%version_%';
③ which mysql |xargs file (linux/unix 系统)
④ echo STATUS|mysql -uroot -ppassword |grep Ver
本文如有错误或不完善的地方请大家多多指正,
留言微信:jem_db 或 QQ:2243967774 皆可,您的批评指正是我写作的最大动力!