关于Mysql(MariaDB)的基本操作命令指南

MYSQL基本命令操作

1.登录方法:

mysql -u root -p

2.显示所有数据库:

show databases;

3.操作指定数据库(以information_schema为例)

use information_schema

4.显示所有的表

show tables;

5.显示表结构(以users表为例)

discribe tables;

6.查询所有数据库的大小:

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;

7.查询指定数据库的大小(以zabbix为例):

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix';

8.查询指定数据库中所有表的大小(以zabbix为例):

SELECT TABLE_NAME,DATA_LENGTH+INDEX_LENGTH,TABLE_ROWS,concat(round((DATA_LENGTH+INDEX_LENGTH)/1024/1024,2), 'MB') as data

FROM information_schema.tables WHERE TABLE_SCHEMA='zabbix' ORDER BY DATA_LENGTH+INDEX_LENGTH desc;

9.查询指定数据库中指定表的大小(以zabbix数据库的history表为例):

select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='zabbix' and table_name='history';``

猜你喜欢

转载自blog.51cto.com/brave8898/2119439