If you know the size of each database, enter the information_schema database
# 1、查询所有数据大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
# 2、查看指定数据库大小 查看 cms_test数据库 存储数据大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables
where TABLE_SCHEMA='cms_test';
# 3、查看指定数据库的某个表的大小 比如查看数据库home中 members 表的大小
select concat(round(sum(data_length/1024/1024),2),‘MB’) as data from tables where table_schema=‘数据库’ and table_name=‘表名’;
-- DATA_LENGTH:数据长度(字节单位)
-- /1024/1024:字节转换为M
-- round:四舍五入,留2位小数
-- concat 拼接MB
View the specified database capacity
select
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024/1024, 2)) as '数据容量(G)',
sum(truncate(index_length/1024/1024/1024, 2)) as '索引容量(G)'
from information_schema.tables
where table_schema='mysql';
Take a look at
the test environment data 50G + index 10G, the database capacity is almost 80G, which is barely enough.
The online environment data is 40G + index 6G, and the database capacity is also 80G
View the size of each database capacity
select
table_schema as '数据库',
sum(table_rows) as '记录数',
sum(truncate(data_length/1024/1024/1024, 2)) as '数据容量(G)',
sum(truncate(index_length/1024/1024/1024, 2)) as '索引容量(G)'
from information_schema.tables
group by table_schema
database command
1. Migrate one database to another
# 导入测试环境数据库 到本地 scucess
mysqldump -hxxx -P端口 -u用户名 -p密码 数据库 | mysql -uroot -p3306 authority
# 本地测试 jwt 迁移到 jtw2 数据库需要存在才行 scucess
mysqldump -uroot -p3306 jwt | mysql -uroot -p3306 jwt2