mysql mysqldump数据库备份与还原

互联网十八般武艺 互联网十八般武艺

mysqldump是mysql一个数据库常用工具,我们经常用它来实现数据和备份如,数据导入导出,本文章来介绍最基本数据库导出与表导现的代码.

  1. #mysqldump 数据库名 >数据库备份名
  2. #mysqldump -A -u用户名 -p密码 数据库名>数据库备份名
  3. #mysqldump -d -A --add-drop-table -uroot -p >xxx.sql

导出整个数据库database,代码如下:

mysqldump –opt -uroot -ppassword database > dump.sql

导出单个数据表table,代码如下:

mysqldump –opt –add-drop-table -uroot -ppassword database table > dump.sql

国外网站数据导入导出说明:For the impatient, here is the quick snippet of how backup and restore MySQL database using mysqldump:代码如下:

  1. backup:#mysqldump-uroot-p[root_password][database_name]>dumpfilename.sql
  2. restore:#mysql-uroot-p[root_password][database_name]<dumpfilename.sql

Backup a single database:

This example takes a backup of sugarcrm database and dumps the output to sugarcrm.sql,代码如下:

  1. #mysqldump-uroot-ptmppasswordsugarcrm>sugarcrm.sql
  2. #mysqldump-uroot-p[root_password][database_name]>dumpfilename.sqlThesugarcrm.sqlwillcontaindroptable,createtableandinsertcommandforallthetablesinthesugarcrmdatabase.Followingisapartialoutputofsugarcrm.sql,showingthedumpinformationofaccounts_contactstable:
  3. --代码如下
  4. --
  5. --Tablestructurefortable`accounts_contacts`
  6. --
  7. DROPTABLEIFEXISTS`accounts_contacts`;
  8. SET@saved_cs_client=@@character_set_client;
  9. SETcharacter_set_client=utf8;
  10. CREATETABLE`accounts_contacts`(
  11. `id`varchar(36)NOTNULL,
  12. `contact_id`varchar(36)defaultNULL,
  13. `account_id`varchar(36)defaultNULL,
  14. `date_modified`datetimedefaultNULL,
  15. `deleted`tinyint(1)NOTNULLdefault'0',
  16. PRIMARYKEY(`id`),
  17. KEY`idx_account_contact`(`account_id`,`contact_id`),
  18. KEY`idx_contid_del_accid`(`contact_id`,`deleted`,`account_id`)
  19. )ENGINE=MyISAMDEFAULTCHARSET=utf8;
  20. SETcharacter_set_client=@saved_cs_client;
  21. --
  22. --Dumpingdatafortable`accounts_contacts`
  23. --
  24. LOCKTABLES`accounts_contacts`WRITE;
  25. /*!40000ALTERTABLE`accounts_contacts`DISABLEKEYS*/;
  26. INSERTINTO`accounts_contacts`VALUES('6ff90374-26d1-5fd8-b844-4873b2e42091',
  27. '11ba0239-c7cf-e87e-e266-4873b218a3f9','503a06a8-0650-6fdd-22ae-4873b245ae53',
  28. '2008-07-2305:24:30',1),
  29. ('83126e77-eeda-f335-dc1b-4873bc805541','7c525b1c-8a11-d803-94a5-4873bc4ff7d2',
  30. '80a6add6-81ed-0266-6db5-4873bc54bfb5','2008-07-2305:24:30',1),
  31. ('4e800b97-c09f-7896-d3d7-48751d81d5ee','f241c222-b91a-d7a9-f355-48751d6bc0f9',
  32. '27060688-1f44-9f10-bdc4-48751db40009','2008-07-2305:24:30',1),
  33. ('c94917ea-3664-8430-e003-487be0817f41','c564b7f3-2923-30b5-4861-487be0f70cb3',
  34. 'c71eff65-b76b-cbb0-d31a-487be06e4e0b','2008-07-2305:24:30',1),
  35. ('7dab11e1-64d3-ea6a-c62c-487ce17e4e41','79d6f6e5-50e5-9b2b-034b-487ce1dae5af',--phpfensi.com
  36. '7b886f23-571b-595b-19dd-487ce1eee867','2008-07-2305:24:30',1);
  37. /*!40000ALTERTABLE`accounts_contacts`ENABLEKEYS*/;
  38. UNLOCKTABLES;

相关广告
  • mysql mysqldump数据库备份与还原 mysql mysqldump数据库备份与还原 mysql mysqldump数据库备份与还原
相关阅读

mysqldump数据库备份还原语句

2019/10/10 17:34:02 | 谷歌SEO算法 | SEO工具

mysqldump数据备份与还原详细介绍

2019/10/10 17:33:20 | 谷歌SEO算法 | 搜索引擎

mysqldump数据库备份与还原方法

2019/10/10 17:33:19 | 谷歌SEO算法 | SEO

mysql mysqldump数据库备份与还原

2019/10/10 17:33:18 | 谷歌SEO算法 | SEO知识