gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 11:03:23 26 4
gpt4 key购买 nike

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com