使用php将mysql转储导入到计算机

使用php将mysql转储导入到计算机,php,mysql,Php,Mysql,我需要创建一个install.php文件,让我的讲师将数据库转储(我将提供)导入到他的机器上 SQL转储将被称为dump.SQL,我有一个config.php文件,其中包含凭据和install.php,该文件应用于导入SQL转储 config.php <?php //defining variables define('DB_HOST','localhost'); define('DB_USER','root'); define('DB_PASS','');

我需要创建一个install.php文件,让我的讲师将数据库转储(我将提供)导入到他的机器上

SQL转储将被称为dump.SQL,我有一个config.php文件,其中包含凭据和install.php,该文件应用于导入SQL转储

config.php

<?php
    //defining variables
    define('DB_HOST','localhost');
    define('DB_USER','root');
    define('DB_PASS','');
    define('DB_NAME','database'); 

    //connection to mysql server
    $conn=mysql_connect(DB_HOST, DB_USER, DB_PASS) or die ("Error connecting to server: ".mysql_error());
?>

install.php

<?php

    include_once ('config.php');

    echo "starting install...";

    //insert dbdump in the same folder as install.php (put them in a separate folder)
    $command = "C:\xampp\mysql\bin\mysql -u".DB_USER." -p".DB_PASS." < dump.sql";
    //echo $command;
    exec($command, $output, $return_var);

    $output = shell_exec($command);

    if ($output) {
    echo "database created";
    }

?>

我正在使用$command变量,因为我读到这是一个标准变量,它复制了cmd命令,但是数据库仍然没有被创建

我测试了同一个命令“mysql-uroot 有人能指出问题所在吗


谢谢

1。在xampp文件夹中查找mysql.exe:

E:\xampp\mysql\bin\mysql.exe
2.在xampp文件夹中打开CMD

E:\xampp\mysql\bin\mysql.exe
3.在CMD中使用以下内容

mysql -h localhost -u root -p
show databases;
4.显示数据库

mysql -h localhost -u root -p
show databases;
例如:

 MariaDB [(none)]> show databases;
+--------------------------+
| Database                 |
+--------------------------+
| information_schema       |
| mysql                    |
| performance_schema       |
| phpmyadmin               |
| test                     |
+--------------------------+
7 rows in set (0.101 sec)

MariaDB [(none)]>
5.使用数据库

use databases;
范例

MariaDB [(none)]> use test
Database changed
MariaDB [test]>
MariaDB [test]> >source E:\your\sql\file\path\mysqlfile.sql
6.Dump数据库 最后给出sql文件的源路径

source E:\your\sql\file\path\mysqlfile.sql
范例

MariaDB [(none)]> use test
Database changed
MariaDB [test]>
MariaDB [test]> >source E:\your\sql\file\path\mysqlfile.sql

请它们不再得到维护,而是在使用。改为学习并使用。是否应该有
-u用户名
u
用户名之间的空格以及
-p
密码之间的空格_mulder@JayBlanchard对此不确定,对于unix,它肯定应该是
-pPASSWORD
,否则会提示输入密码。Hmmm。很难说,从未使用过
-ppasword