phpMyAdmin导出功能如何工作? [英] How does the phpMyAdmin export feature work?

查看:120
本文介绍了phpMyAdmin导出功能如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想创建一个与phpMyAdmin中的Export选项卡具有相同功能的PHP函数,该怎么办?我不知道是否有执行此操作的MySQL函数,或者phpMyAdmin是否只是手动构建导出文件(在SQL中).没有外壳访问.只是使用PHP.

If I were to want to create a PHP function that does the same thing as the Export tab in phpMyAdmin, how could I do it? I don't know if there is a MySQL function that does this or if phpMyAdmin just builds the export file (in SQL that is) manually. Without shell access. Just using PHP.

我尝试了 mysqldump 的文档,但是似乎需要使用外壳.我不太确定那是什么-也许我的问题是:您如何使用shell?

I tried the documentation for mysqldump, but that seemed to require using the shell. I'm not quite sure what that even is -- maybe my question is: how do you use shell?

我愚蠢的想法是允许非技术用户使用MySQL在一个服务器(例如本地主机)上构建站点,然后将站点,数据库以及所有内容导出到另一台服务器(例如,远程服务器).

My silly idea is to allow non-technical users to build a site on one server (say a localhost) using MySQL then export the site, database and all, to another server (eg. a remote server).

我认为我对导入过程非常清楚.

I think I'm pretty clear on the Import process.

推荐答案

您可以检查phpMyAdmin源代码(开放源代码软件的优势).在library/export/sql.php脚本文件中检查export.php脚本和支持功能.

You can check the phpMyAdmin source code (an advantage of open-source software). Check the export.php script and the supporting functions in the libraries/export/sql.php script file.

总而言之,phpMyAdmin的作用是:

In summary, what phpMyAdmin does is:

  • 获取给定数据库中的表列表(SHOW TABLES FROM ...),
  • 获取每个表的创建查询(SHOW CREATE TABLE ...),
  • 解析它并从中提取列定义
  • 获取所有数据(SELECT * FROM ...)
  • 根据列数据构建查询.

我已经为自己的应用程序编写了类似的代码(出于备份目的,当phpMyAdmin的GPL许可不允许我使用它时),但是我使用DESCRIBE来获取列定义.我认为他们宁愿解析SHOW CREATE TABLE输出,因为它包含比DESCRIBE输出更多的信息.

I've written similar code for my own apps (for backup purposes, when the GPL license of phpMyAdmin doesn't allow me to use it), however I use DESCRIBE to get column definitions. I think they rather parse the SHOW CREATE TABLE output because contains more information than DESCRIBE output.

这种生成SQL语句的方式需要谨慎处理转义,但是它具有一定的灵活性,因为您可以转换类型,过滤或清理数据等.它比使用mysqldump之类的工具要慢很多并且应该注意不要消耗所有可用内存(尽快写,经常写,不要将所有内容都保留在内存中).

This way to generate SQL sentences requires a bit of care to handle the escaping but it allows for some flexibility, as you can convert types, filter or sanitize data, etc. It is also a lot slower than using a tool like mysqldump and you should take care of not consuming all available memory (write soon, write often, don't keep everything in memory).

如果要实现从服务器到服务器的迁移过程,则可能需要一些shell脚本并直接调用mysqldump,这样会更容易,除非您将使用PHP进行所有操作.

If you will implement a migration process (from server to server) maybe it would be easier to do it with some shell scripting and calling mysqldump directly, unless you will do everything with PHP.

这篇关于phpMyAdmin导出功能如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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