如何在出现1045错误时在SQL中导出运行查询的结果?

时间:2016-01-26 13:53:51

标签: mysql sql database export

SELECT wp_posts.ID,
       wp_posts.post_author,
       wp_users.ID,
       wp_users.display_name
FROM   wp_posts,
       wp_users
WHERE  wp_posts.post_author = wp_users.ID
       AND wp_users.ID != 1 

这给了我结果

result

现在我想导出我在phpmyadmin中从查询中获得的结果。

为此,我按照下面给出的答案做了这个。

SELECT wp_posts.ID,
       wp_posts.post_author,
       wp_users.ID,
       wp_users.display_name
FROM   wp_posts,
       wp_users
WHERE  wp_posts.post_author = wp_users.ID
       AND wp_users.ID != 1 
INTO OUTFILE 'D:\backup\export.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'

它给了我错误

  

1045 - 拒绝访问用户'用户名' @' localhost' (使用密码:是)

1 个答案:

答案 0 :(得分:2)

像这样的东西

SELECT wp_posts.ID,
       wp_posts.post_author,
       wp_users.ID,
       wp_users.display_name
FROM   wp_posts,
       wp_users
WHERE  wp_posts.post_author = wp_users.ID
       AND wp_users.ID != 1 
INTO OUTFILE 'c:\\.....' --path to store the export data
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'

可以找到更多信息here