【问题标题】:I am trying to export a MySQL table, but I am receiving --secure-file-priv我正在尝试导出 MySQL 表,但我收到了 --secure-file-priv
【发布时间】:2017-06-09 11:43:27
【问题描述】:

我知道还有很多其他类似的问题,但我几乎查看了所有其他帖子,所有其他建议都没有奏效。

我目前使用的是 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。

【问题讨论】:

    标签: mysql database command-line terminal


    【解决方案1】:

    所以我决定不用担心命令行,并创建了一个 .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>
    

    【讨论】:

      猜你喜欢
      • 2016-09-03
      • 2020-05-05
      • 2017-04-20
      • 2019-08-07
      相关资源
      最近更新 更多