需要帮助来备份 phpMyAdmin 数据库

发布于 2024-11-07 20:51:44 字数 462 浏览 0 评论 0原文

我想从 php 文件备份我的数据库...
我使用 phpMyAdmin 作为后端。我想从该数据库创建 Excel 文件,可以吗?是的那怎么办?给我一些建议,提前谢谢...
我的另一个问题是
如果我正在运行这个 php 代码,那么当它存储该文件时..?我已经检查了不在里面的 phpMyAdmin bt,代码如下

<?php
include 'config.php';
include 'opendb.php';
$tableName  = 'mypet';
$backupFile = 'backup/mypet.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $login_master";
$result = mysql_query($query);

include 'closedb.php';
?> 

i want to backup my database from php file...
i am using phpMyAdmin as back end. i want to create excel file from that data base is it possible? yes then how? give me some suggestion on it thanks in advance...
my one more querty is:
if i am running this php code then when it store that file..? i've checked into the phpMyAdmin bt that was not inside that the code is as below

<?php
include 'config.php';
include 'opendb.php';
$tableName  = 'mypet';
$backupFile = 'backup/mypet.sql';
$query      = "SELECT * INTO OUTFILE '$backupFile' FROM $login_master";
$result = mysql_query($query);

include 'closedb.php';
?> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不再让梦枯萎 2024-11-14 20:51:44

新的备份链接:
Mysqli: https://www.dropbox.com/s/s9qmvj7um4h5tdx/ backup.php?dl=0
Mysql:https://www.dropbox.com/s/n14p9uf9wc09ow0/ index.php?dl=0

将此文件放在您的 WWW 文件夹中,然后运行它,如果发生错误,请不要惊慌,但您的数据库已备份在 www 文件夹中

    /* backup the db OR just a table */
    function backup_tables($host,$user,$pass,$name,$tables = '*')
    {

        $link = mysql_connect($host,$user,$pass);
        mysql_select_db($name,$link);

        //get all of the tables
        if($tables == '*')
        {
            $tables = array();
            $result = mysql_query('SHOW TABLES');
            while($row = mysql_fetch_row($result))
            {
                $tables[] = $row[0];
            }
        }
        else
        {
            $tables = is_array($tables) ? $tables : explode(',',$tables);
        }

        //cycle through
        foreach($tables as $table)
        {
            $result = mysql_query('SELECT * FROM '.$table);
            $num_fields = mysql_num_fields($result);

            $return.'='. 'DROP TABLE '.$table.';';
            $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
            $return.= "\n\n".$row2[1].";\n\n";

            for ($i = 0; $i < $num_fields; $i++) 
            {
                while($row = mysql_fetch_row($result))
                {
                    $return.= 'INSERT INTO '.$table.' VALUES(';
                    for($j=0; $j<$num_fields; $j++) 
                    {
                        $row[$j] = addslashes($row[$j]);
                        $row[$j] = ereg_replace("\n","\\n",$row[$j]);
                        if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
                        if ($j<($num_fields-1)) { $return.= ','; }
                    }
                    $return.= ");\n";
                }
            }
            $return.="\n\n\n";
        }

        //save file

        $handle = fopen('store-'.date("Y-m-d-H-i-s").'-'.(implode(',',$tables)).'.sql','w+');
        fwrite($handle,$return);
        fclose($handle);
    }
header("http://localhost/store/");
    ?>

New backup link :
Mysqli : https://www.dropbox.com/s/s9qmvj7um4h5tdx/backup.php?dl=0
Mysql :https://www.dropbox.com/s/n14p9uf9wc09ow0/index.php?dl=0

Put this file in your WWW folder and just run it dont panic if error occured but you database is backuped in www folder

    /* backup the db OR just a table */
    function backup_tables($host,$user,$pass,$name,$tables = '*')
    {

        $link = mysql_connect($host,$user,$pass);
        mysql_select_db($name,$link);

        //get all of the tables
        if($tables == '*')
        {
            $tables = array();
            $result = mysql_query('SHOW TABLES');
            while($row = mysql_fetch_row($result))
            {
                $tables[] = $row[0];
            }
        }
        else
        {
            $tables = is_array($tables) ? $tables : explode(',',$tables);
        }

        //cycle through
        foreach($tables as $table)
        {
            $result = mysql_query('SELECT * FROM '.$table);
            $num_fields = mysql_num_fields($result);

            $return.'='. 'DROP TABLE '.$table.';';
            $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
            $return.= "\n\n".$row2[1].";\n\n";

            for ($i = 0; $i < $num_fields; $i++) 
            {
                while($row = mysql_fetch_row($result))
                {
                    $return.= 'INSERT INTO '.$table.' VALUES(';
                    for($j=0; $j<$num_fields; $j++) 
                    {
                        $row[$j] = addslashes($row[$j]);
                        $row[$j] = ereg_replace("\n","\\n",$row[$j]);
                        if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
                        if ($j<($num_fields-1)) { $return.= ','; }
                    }
                    $return.= ");\n";
                }
            }
            $return.="\n\n\n";
        }

        //save file

        $handle = fopen('store-'.date("Y-m-d-H-i-s").'-'.(implode(',',$tables)).'.sql','w+');
        fwrite($handle,$return);
        fclose($handle);
    }
header("http://localhost/store/");
    ?>
梨涡 2024-11-14 20:51:44

这很容易。

  1. 在phpmyadmin图形界面上,选择要保存的数据库。
  2. 单击顶部的导出选项卡。
  3. 从右侧的框中选择“excel”。
  4. 点击底部的go

完毕。

It's pretty easy.

  1. On the phpmyadmin graphic interface, select the database you want to save.
  2. Click on the export tab at the top.
  3. Select "excel" from the box you'll find on the right.
  4. Click go at the bottom.

Done.

素染倾城色 2024-11-14 20:51:44

选择数据库后,您应该单击“导出”选项卡。您将看到一个包含许多选项的页面(要导出哪些表、导出文件的名称、文件类型、是 excel 还是 sql 还是其他...)。

无论如何,如果可能的话,我建议使用命令行。

Once you have selected your database, you should click on "Export" tab. You will be shown a page with a number of options (which tables to export, the name of the export file, the type of file, whether excel or sql or whatever...).

Anyway, I suggest to use the command line if possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文