Answers:
倾倒
mysqldump db_name table_name > table_name.sql
从远程数据库转储
mysqldump -u <db_username> -h <db_host> -p db_name table_name > table_name.sql
进一步参考:
http://www.abbeyworkshop.com/howto/lamp/MySQL_Export_Backup/index.html
恢复
mysql -u <user_name> -p db_name
mysql> source <full_path>/table_name.sql
或一行
mysql -u username -p db_name < /path/to/table_name.sql
图片来源:John McGrath
倾倒
mysqldump db_name table_name | gzip > table_name.sql.gz
恢复
gunzip < table_name.sql.gz | mysql -u username -p db_name
尝试
for line in $(mysql -u... -p... -AN -e "show tables from NameDataBase");
do
mysqldump -u... -p.... NameDataBase $line > $line.sql ;
done
您可以使用以下代码:
本示例对sugarcrm数据库进行备份并将输出转储到sugarcrm.sql
# mysqldump -u root -ptmppassword sugarcrm > sugarcrm.sql
# mysqldump -u root -p[root_password] [database_name] > dumpfilename.sql
sugarcrm.sql将包含dropcr表,create table以及sugarcrm数据库中所有表的insert命令。以下是sugarcrm.sql的部分输出,显示accounts_contacts表的转储信息:
-
accounts_contacts
DROP TABLE IF EXISTS `accounts_contacts`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `accounts_contacts` (
`id` varchar(36) NOT NULL,
`contact_id` varchar(36) default NULL,
`account_id` varchar(36) default NULL,
`date_modified` datetime default NULL,
`deleted` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `idx_account_contact` (`account_id`,`contact_id`),
KEY `idx_contid_del_accid` (`contact_id`,`deleted`,`account_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
--
您可以mysqldump
从命令行使用:
mysqldump -u username -p password dbname tablename > "path where you want to dump"
您还可以使用MySQL Workbench:
转到左侧>数据导出>选择架构>选择表,然后单击导出
mysqldump db_name table_name | gzip > table_name.sql.gz
恢复:gunzip < table_name.sql.gz | mysql -u username -p db_name