简体   繁体   English

使用SQL将数据库导出到.CSV

[英]Exporting database to .CSV using SQL

I am working on a project that requires an admin to be able to export a table from a database to .csv format. 我正在一个需要管理员能够将表从数据库导出为.csv格式的项目。 However when I try to run the query below in myphpadmin as a test i receive the following message with a big green check mark: 但是,当我尝试在myphpadmin中运行以下查询作为测试时,收到带有绿色绿色复选标记的以下消息:

MySQL returned an empty result set (ie zero rows). MySQL返回一个空结果集(即零行)。 (Query took 0.0010 sec) (查询耗时0.0010秒)

The table has over 60 records. 该表有60多个记录。 The query i used is below: 我使用的查询如下:

 SELECT * FROM `User`
 INTO OUTFILE 'C:\Users\np\Desktop\test.csv'
 FIELDS TERMINATED BY ','
 ENCLOSED BY '"'
 LINES TERMINATED BY '\n'

Also the file is not created in the location specified. 同样,该文件未在指定位置创建。

Thank you in advance :) 先感谢您 :)

  1. Change 更改

     INTO OUTFILE 'C:\\Users\\np\\Desktop\\test.csv' 

    to

     INTO OUTFILE 'C:\\\\Users\\\\np\\\\Desktop\\\\test.csv' ^^ ^^ ^^ ^^ 
  2. Make sure that account under which mysql process is running has enough permissions to write to a destination directory 确保运行mysql进程的帐户具有足够的权限来写入目标目录

  3. Make sure that you don't already have a file with the same in the target directory. 确保目标目录中没有相同的文件。 MySql won't replace the file. MySql不会替换该文件。 It only creates file afresh. 它仅重新创建文件。

Why don't you just use the phpMyAdmin export functionality? 您为什么不只使用phpMyAdmin导出功能? Look for the Export tab from with a database or table. 从数据库或表中查找“导出”选项卡。 There's also a link from any results page (for instance, if you create a custom SQL query). 任何结果页面上都有一个链接(例如,如果您创建自定义SQL查询)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM