mysql - 我正在尝试导出 MySQL 表,但收到 --secure-file-priv

标签 mysql database command-line terminal

我知道还有很多其他类似的问题,但我几乎研究了所有其他帖子,并且所有其他建议都不起作用。

我目前使用的是 macOS Sierra 版本 10.12.2

MySQL版本5.7.17

选择@@GLOBAL.secure_file_priv;并显示“secure_file_priv”等变量;显示 secure_file_priv = 为 NULL。

我的系统上没有 my.cnf 文件(查找:my.cnf:没有这样的文件或目录)

我读过很多文章提到更改 secure_file_priv 的值,但我找不到它。

我在这里讨论了以下帖子:

Solution 1

Solution 2

Solution 3

我希望这个问题能够得到解答,因为它与我的情况相关:

Solution 4

Solution 5

在一天结束时,看起来更改 secure_file_priv 是开始的地方,我只是找不到它。

我确信上述内容的 OUTFILE 位置可能不正确,但那是因为我不知道我在哪里可以访问文件,因为我不知道如何更改/定位 secure_file_priv。

最佳答案

因此,我决定不再担心命令行,而是创建了一个 .php 文件,将 MySQL 数据库直接导出到 Excel 中。

解决方案的灵感来自以下内容:(向这个家伙表达一些爱!)

作者:Shahroze Nawaz

日期:2016 年 11 月 8 日

标题:如何使用 PHP 和 MySQL 导入和导出 CSV 文件

网址:https://www.cloudways.com/blog/import-export-csv-using-php-and-mysql/

这是主index.php

<pre>

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" crossorigin="anonymous">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script>
    </head>

    <body>
        <div id="wrap">
            <div class="container">
                <div class="row">

        <!--Database Table Display-->
                    <?php 
                        include 'database_table.php';
                    ?> 
        <!--End Import Form Button-->

        <!--Export Form Button-->
                    <form class="form-horizontal" action="export.php" method="POST" name="upload_excel"   
                          enctype="multipart/form-data">
                        <div class="form-group">
                            <div class="col-md-4 col-md-offset-4">
                                <input type="submit" name="Export" class="btn btn-success" value="Export to Excel"/>
                            </div>
                        </div>                    
                    </form> 
        <!--End Export Form Button-->

                </div>
            </div>
        </div>
    </body>

    </html>

</pre>

这是表单操作的export.php:

<pre>
      $dbhost = "******";
      $dbuser = "******";
      $dbpass = "******";
      $dbname = "******";
      $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); 

      $selection = "SELECT * <table name>";
      $result = mysqli_query($connection, $selection);

      if(isset($_POST["Export"])) {
            header('Content-Type: text/csv; charset=utf-8');  
            header('Content-Disposition: attachment; filename = leads.csv');

            $output = fopen("php://output", "w"); 
            fputcsv($output, array('ID', 'First Name', 'Last Name', 'Email', 'Phone', 'State', 'Specialty', 'Sourcecode', 'Date'));  

            while($row = mysqli_fetch_assoc($result)) {  
                 fputcsv($output, $row);  
            }  
            fclose($output);  
       }
</pre>

这是打印到 index.php 文件中的数据库表,它显示了具有引导格式的 MySQL 数据库:

<pre>

    <?php
        $dbhost = "******";
        $dbuser = "******";
        $dbpass = "******";
        $dbname = "******";
        $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); 

        $selection = "SELECT * <table name>";
        $result = mysqli_query($connection, $selection);

        if (mysqli_num_rows($result) > 0) {
              echo "<div class='table-responsive'>
                          <table id='myTable' class='table table-striped table-bordered'>
                                <thead>
                                      <tr>
                                            <th>ID</th>
                                            <th>First Name</th>
                                            <th>Last Name</th>
                                            <th>Email</th>
                                            <th>Phone</th>
                                            <th>State</th>
                                            <th>Specialty</th>
                                            <th>Sourcecode</th>
                                            <th>Time</th>
                                      </tr>
                                </thead>

                                <tbody>";
                                while($row = mysqli_fetch_assoc($result)) {
                                      echo "<tr>
                                            <td>" . $row['id']."</td>
                                            <td>" . $row['first_name']."</td>
                                            <td>" . $row['last_name']."</td>
                                            <td>" . $row['email']."</td>
                                            <td>" . $row['phone']."</td>
                                            <td>" . $row['state']."</td>
                                            <td>" . $row['specialty']."</td>
                                            <td>" . $row['source_code']."</td>
                                            <td>" . $row['date_submitted']."</td>
                                      </tr>";        
                          }

                                echo "</tbody>
                          </table>
                    </div>";

        } else {
              echo "You have no records...";
        }
    ?>

</pre>

关于mysql - 我正在尝试导出 MySQL 表,但收到 --secure-file-priv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41832196/

相关文章:

sql - 这个 ADO OPEN 方法有什么作用?

mysql - 使用不同的where条件对同一列进行计数

sql - 高效的 SQL Server 存储过程

linux - 使用du -sh *命令时如何根据子目录的大小排序?

linux - 如何在 Linux 中打开/切换到第 10 个 screen session ?

java - 如何在 JFreeChart 中显示过滤后的数据

mysql - 如何在linux服务器上找到mysql服务

php - 我需要有关如何让我的插入代码在 php 和 mysql 中工作的提示

database - 是否可以将公司数据库连接到 Odoo 9 (OpenERP)?

Java Runtime.exec 在 Linux 中因空间而失败