PHP下载MySQL数据库备份
我想让客户能够手动下载其数据库的备份。我正在使用 PHP 和 MySQL 对该网站进行编码。因此,管理员用户登录后,菜单中会出现一个链接,用于将 .sql 文件下载到本地计算机。我怎样才能用 PHP 完成这个任务?
I want to give a client the ability to manually download a backup of his database. I am coding the site using PHP and MySQL. So after the admin user has logged in there would be a link in the menu to download a .sql file to the local computer. How can I accomplish this with PHP?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试从 PHP 备份数据库可能会变得混乱,最好让 MySql 处理这个问题,告诉 mysql 执行此操作的最佳方法是使用 shell 脚本:
然后告诉 php 告诉操作系统执行此脚本并等待其完成,这通常是通过
exec
或system
完成的,例如:然后您可以简单地将脚本创建的文件发送到浏览器对于该用户。
This can get messy trying to back up a database from PHP, you would be better of letting MySql handle this, and the best way to tell mysql to do this is with a shell script:
and then you tell php to tell the operating system to execute this script and wait for it to be done, this is usually done with
exec
orsystem
such as:Then you can simply send the file created by the script to the browser for that user.