一、数据库的导入导出
1、导出某数据库:
mysqldump -h 192.168.1.5 -u root -p database_name > file_name
./mysqldump -uroot -p weatherplus >weatherplus_2013-04-12_bak.sql
[root@liangy local]# cd mysql
[root@liangy mysql]# cd bin
[root@liangy bin]# ./mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1485 to server version: 5.0.26-standard-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> source /usr/local/weather.sql;
2、导出某数据库结构(只有数据结构,没有数据):
mysqldump -h 192.168.1.5 -u root -p -d --add-drop-table database_name > file_name
(-d 没有数据 --add-drop-table 在每个create语句之前增加一个drop table)
3、导出某表:
mysqldump -h 192.168.1.5 -u root -p database_name table_name1 talbe_name2... > file_name
4、导入某数据库:
mysql -h 192.168.1.10 -u root -p
CREATE DATABASE database_name;
use database_name;
source file_name;
5、导入某表:
mysql -h 192.168.1.10 -u root -p
use database_name;
source file_name;
二、查看数据库大小
要想知道每个数据库的大小的话,步骤如下:
1、进入information_schema 数据库(存放了其他的数据库的信息)
use information_schema;
2、查询所有数据的大小:
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables;
3、查看指定数据库的大小:
比如查看数据库home的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home';
4、查看指定数据库的某个表的大小
比如查看数据库home中 members 表的大小
select concat(round(sum(data_length/1024/1024),2),'MB') as data from tables where table_schema='home' and table_name='members';