Overview of MySQL backup by table backup

Source: Internet
Author: User
Tags mysql backup

The following articles mainly introduce MySQL Backup Based on table backup. This article uses the actual application code to introduce MySQL Backup Based on table backup, the following describes the main content of the article, hoping to help you in this aspect.

 
 
  1. <?php 
  2. function datatosql($table)   
  3. {   
  4. global $db;   
  5. $tabledump = "DROP TABLE IF EXISTS $table;\n";   
  6. $createtable = $db->query("SHOW CREATE TABLE $table");   
  7. $create = $db->fetch_array($createtable);   
  8. $tabledump .= $create[1].";\n\n";   
  9. $rows = $db->query("SELECT * FROM $table");   
  10. $numfields = $db->num_fields($rows);   
  11. $numrows = $db->num_rows($rows);   
  12. while ($row = $db->fetch_array($rows)){   
  13. $comma = "";   
  14. $tabledump .= "INSERT INTO $table VALUES(";   
  15. for($i = 0; $i < $numfields; $i++)   
  16. {   
  17. $tabledump .= $comma."'".MySQL_escape_string($row[$i])."'";   
  18. $comma = ",";   
  19. }   
  20. $tabledump .= ");\n";   
  21. }   
  22. $tabledump .= "\n";   
  23. return $tabledump;   
  24. }  

The above content is related to MySQL backup-based on the introduction of table backup, I hope you will have some gains.

The above content is related to MySQL backup-based on the introduction of table backup, I hope you will have some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.