备份mysql数据库并下载为文件 [英] Backup a mysql database and download as a file
问题描述
如何使用PHP代码备份mysql数据库并将其下载为.sql文件
How to backup the mysql database and download it as a .sql file by using PHP Codes
推荐答案
一个非常简单的解决方案如下(第一个示例): http://www .php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx
A very simple solution would be something like (first example): http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx
自然,这只会对表进行数据转储.
Naturally this will only make a Data dump of the table.
您可以做的是使用以下代码:
What you could do is use this code:
http://snipplr.com/view/173/mysql-dump/
此代码的作用实际上是获取表的说明(即其结构),创建所有表并推送数据.就像其他任何工具一样.
What this code does is actually gets a description of the table (i.e its structure), creates all the tables and pushes data. pretty much like any other tool does.
然后只需将其从字符串保存到文件(例如,取决于您的喜好和需求,例如file_put_contents()或类似内容)
Then its just a matter of saving it from string to a file (file_put_contents() for instance or something similar, depending on your preference and need)
这篇关于备份mysql数据库并下载为文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!