Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 156853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:24:00+00:00 2026-05-11T10:24:00+00:00

I am trying to capture the output of a SQL query in MySQL, to

  • 0

I am trying to capture the output of a SQL query in MySQL, to a text file using the following query.

select count(predicate),subject from TableA group by subject into outfile '~/XYZ/output.txt'; 

I get the following error.

ERROR 1045 (28000): Access denied for user ‘username’@’%’ (using password: YES)

Any idea, where am I going wrong? Is it some permission related issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:24:00+00:00Added an answer on May 11, 2026 at 10:24 am

    Outfile is it’s own permission in mysql.

    If you have ALL it’s included.

    But if you just have a safe collection such as SELECT, INSERT, UPDATE, DELETE, DROP, CREATE, but not OUTFILE, ‘into outfile’ will not work in queries.

    The reason for this is that accessing files from within MySQL, even for write purposes, has certain security risks, because if you access a file from mysql you can access any file the mysql user has access to, thereby bypassing user-based file permissions.

    To get around this, you can run your query directly into the output of whatever shell/language you’re using to run the sql with.

    Here is a *nix example

    >$ echo 'select count(predicate),subject from TableA group by subject'  | mysql -u yourusername -p yourdatabasename > ~/XYZ/outputfile.txt 

    But do it all on one line without the ‘\’ or use the ‘\’ to escape the line break.

    What’s happening here is that you’re running a query into the mysql client and it’s spitting out the result, then you’re directing the output to a file. So the file is never called from within mysql, it’s called after mysql runs.

    So use mysql to get the information and THEN dump the data to the file from your own user shell and you’ll be fine.

    Or find a way to get yourself the outfile mysql permission, either way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to capture dvdauthor's output to a file. So far i found this
I'm trying to run curl as a process and capture the output from the
I'm trying to capture output from a console application by running it in a
I have no idea why this is hanging. I'm trying to capture output from
I'm trying to capture standard output of a command to a file-like object in
Trying to redirect a subprocess' output to a file. server.py: while 1: print Count
I have been trying to capture stdout and stderr output from a DLL compiled
I am trying to capture the output from tail in follow mode, where it
I'm trying to capture the output of my controller class (yii framework) the following
I'm trying to call a C program from Java and capture the standard output.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.