Mysql数据库使用量查询及授权
使用量查询
select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2),'MB') as data_size,
concat(truncate(sum(index_length)/1024/1024,2),'MB') as index_size
from information_schema.tables
group by TABLE_SCHEMA
order by data_length desc;
SELECT concat((sum(DATA_LENGTH)+sum(INDEX_LENGTH))/(1024*1024),'M') FROM information_schema.TABLES where TABLE_SCHEMA='DATABASE';
SELECT table_schema,table_name,(data_length/1024/1024),(index_length/1024/1024) FROM information_schema.tables where table_schema='DATABASE' order by data_length;
SELECT sum(DATA_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='DATABASE' AND table_name='TABLE';
SELECT sum(DATA_LENGTH)+sum(INDEX_LENGTH) FROM information_schema.TABLES where TABLE_SCHEMA='DATABASE' AND table_name='TABLE';
select ENGINE from INFORMATION_SCHEMA.tables where TABLE_SCHEMA='DATABASE' and table_name='TABLE';
常用授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MYSQL@2018';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.%' IDENTIFIED BY 'MYSQL@2018' WITH GRANT OPTION;
- 设置dbadmin账户能从10网段登陆数据库,且拥有所有权限
GRANT ALL PRIVILEGES ON *.* TO dbadmin@'10.%' IDENTIFIED BY 'MYSQL@2018';
- 设置dbreader账户能从10网段登陆数据库,且拥有只读权限
GRANT SELECT ON *.* TO dbreader@'10.%' IDENTIFIED BY 'MYSQL@2018';
FLUSH PRIVILEGES;
Truncate tables;