mysql进入outfile创建错误

时间:2016-10-22 07:43:45

标签: php mysql

我遇到mysql out文件的问题。

我正在尝试生成表格的CSV文件。由于数据庞大,我需要以最快的方式实现它。

它正在抛出这样的错误。

  

选择错误无法创建/写入文件   '/var/lib/mysql/mydir/uploads/data.csv'(错误代码:2)

这是我的代码。请帮忙

$host = "localhost";
    $username = "user";
    $password = "pass";
    $dbname = "mydb";

    // open connection to mysql database
    $connection = mysqli_connect($host, $username, $password, $dbname) or 
                  die("Connection Error " . mysqli_error($connection));

    $sql = "select user_id,email,username from `engine4_users` into outfile
     './mydir/uploads/data.csv' FIELDS TERMINATED BY ','  
        LINES TERMINATED BY '\n' ";

    try{
        $result = mysqli_query($connection, $sql) or die("Selection Error "
             . mysqli_error($connection));
    }
    catch(exception $e){
        echo $e->getMessage();
    }

0 个答案:

没有答案