导出SQL表的简单方法,无需访问服务器或phpMyADMIN [英] Easy way to export a SQL table without access to the server or phpMyADMIN
问题描述
我需要一种方法来轻松导出,然后将数据从远程服务器导入到MySQL表中。我没有直接访问服务器,并且没有安装诸如phpMyAdmin之类的实用程序。但是,我有能力将PHP脚本放在服务器上。
如何获取数据?
$ b $我问这个问题纯粹是为了记录我的方法。
你可以为此使用SQL:
$ file ='backups / mytable.sql';
$ result = mysql_query(SELECT * INTO OUTFILE'$ file'FROM`## table ##`);
然后只需将浏览器或FTP客户端指向目录/文件(backups / mytable.sql)。这也是一个很好的方式进行增量备份,给定文件名是一个时间戳。例如,
要从该文件中恢复到您的DataBase,您可以使用: / p>
$ file ='backups / mytable.sql';
$ result = mysql_query(LOAD DATA INFILE'$ file'INTO TABLE`## table ##`);
另一个选项是使用PHP在服务器上调用系统命令并运行'mysqldump':
$ file ='backups / mytable.sql';
system(mysqldump --opt -h ## databaseserver ## -u ## username ## -p ## password ## ## database | gzip>$ file);
I need a way to easily export and then import data in a MySQL table from a remote server to my home server. I don't have direct access to the server, and no utilities such as phpMyAdmin are installed. I do, however, have the ability to put PHP scripts on the server.
How do I get at the data?
I ask this question purely to record my way to do it
You could use SQL for this:
$file = 'backups/mytable.sql';
$result = mysql_query("SELECT * INTO OUTFILE '$file' FROM `##table##`");
Then just point a browser or FTP client at the directory/file (backups/mytable.sql). This is also a nice way to do incremental backups, given the filename a timestamp for example.
To get it back in to your DataBase from that file you can use:
$file = 'backups/mytable.sql';
$result = mysql_query("LOAD DATA INFILE '$file' INTO TABLE `##table##`");
The other option is to use PHP to invoke a system command on the server and run 'mysqldump':
$file = 'backups/mytable.sql';
system("mysqldump --opt -h ##databaseserver## -u ##username## -p ##password## ##database | gzip > ".$file);
这篇关于导出SQL表的简单方法,无需访问服务器或phpMyADMIN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!