Check MySQL Database & Tables Size

Check Single Database Size in MySQL:

SELECT table_schema "Database Name", SUM( data_length + index_length)/1024/1024"Database Size (MB)" FROM information_schema.TABLES where table_schema = 'mydb';

Check ALL Database Size in MySQL:

SELECT table_schema "Database Name", SUM(data_length+index_length)/1024/1024
"Database Size (MB)"  FROM information_schema.TABLES GROUP BY table_schema;

Check Single Table Size in MySQL Database:

SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2)
"Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "mydb" AND table_name ="table_one";

Check All Table Size in MySQL Database:

SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2)
"Table Size (MB)" FROM information_schema.TABLES WHERE table_schema = "mydb";
Advertisements

Export MySQL Tables, Import MySQL Database, Add autoincrement to column through Terminal

Export Database

mysqldump -u root -p db > /path/db_backup.sql

Import Database

mysql -u root -ppassword db <  /var/www/tbl.sql

Export table

mysqldump -uroot -ppassword db tbl > /var/www/tbl.sql

Export table with WHERE clause

mysqldump --opt --user=username --password=password db tbl  --where="id>'207856'" > /var/www/tbl.sql

Import table

mysql -u root -ppassword db <  /var/www/tbl.sql

Add Autoincrement

ALTER TABLE tbl MODIFY COLUMN id INT auto_increment;