问题描述
我想将数据库转储到文件中.
I'd like to dump my databases to a file.
某些网站主机不允许远程或命令行访问,因此我必须使用一系列查询来做到这一点.
Certain website hosts don't allow remote or command line access, so I have to do this using a series of queries.
所有相关问题都说使用mysqldump
",这是一个很棒的工具,但是我没有命令行访问此数据库.
All of the related questions say "use mysqldump
" which is a great tool but I don't have command line access to this database.
我希望同时创建CREATE
和INSERT
命令-与mysqldump
基本上具有相同的性能. SELECT INTO OUTFILE
是正确的出行之路,还是我在忽略其他东西-也许这不可能?
I'd like CREATE
and INSERT
commands to be created at the same time - basically, the same performance as mysqldump
. Is SELECT INTO OUTFILE
the right road to travel, or is there something else I'm overlooking - or maybe it's not possible?
推荐答案
使用mysqldump-php
纯PHP解决方案复制mysqldump
可执行文件的功能以解决从基本到中等的复杂性用例-我知道您可能没有远程CLI和/或mysql直接访问,但是只要您可以通过HTTPd请求在主机上的httpd上执行,它就可以工作:
Use mysqldump-php
a pure-PHP solution to replicate the function of the mysqldump
executable for basic to med complexity use cases - I understand you may not have remote CLI and/or mysql direct access, but so long as you can execute via an HTTP request on a httpd on the host this will work:
因此,您应该能够直接在/www/的安全目录中直接运行以下纯PHP脚本,并在其中写入输出文件,并使用wget进行抓取.
So you should be able to just run the following purely PHP script straight from a secure-directory in /www/ and have an output file written there and grab it with a wget.
mysqldump-php-GitHub上的纯PHP mysqldump
PHP示例:
<?php
require('database_connection.php');
require('mysql-dump.php')
$dumpSettings = array(
'include-tables' => array('table1', 'table2'),
'exclude-tables' => array('table3', 'table4'),
'compress' => CompressMethod::GZIP, /* CompressMethod::[GZIP, BZIP2, NONE] */
'no-data' => false,
'add-drop-table' => false,
'single-transaction' => true,
'lock-tables' => false,
'add-locks' => true,
'extended-insert' => true
);
$dump = new MySQLDump('database','database_user','database_pass','localhost', $dumpSettings);
$dump->start('forum_dump.sql.gz');
?>
这篇关于使用查询而不使用mysqldump备份数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!