无需访问服务器或 phpMyADMIN 即可导出 SQL 表的简便方法 [英] Easy way to export a SQL table without access to the server or phpMyADMIN

查看:24
本文介绍了无需访问服务器或 phpMyADMIN 即可导出 SQL 表的简便方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来轻松地将 MySQL 表中的数据从远程服务器导出然后导入到我的家庭服务器.我没有直接访问服务器的权限,也没有安装诸如 phpMyAdmin 之类的实用程序.但是,我可以将 PHP 脚本放在服务器上.

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.

我如何获取数据?

我问这个问题纯粹是为了记录我的做法

推荐答案

您可以为此使用 SQL:

You could use SQL for this:

$file = 'backups/mytable.sql';
$result = mysql_query("SELECT * INTO OUTFILE '$file' FROM `##table##`");

然后只需将浏览器或 FTP 客户端指向目录/文件 (backups/mytable.sql).这也是进行增量备份的好方法,例如给定文件名一个时间戳.

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##`");

另一种选择是使用 PHP 在服务器上调用系统命令并运行 'mysqldump':

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);

这篇关于无需访问服务器或 phpMyADMIN 即可导出 SQL 表的简便方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆