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

  • Home
  • SEARCH
  • 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 8914625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:46:09+00:00 2026-06-15T04:46:09+00:00

I am trying to dump an output from from a MYSQL view into a

  • 0

I am trying to dump an output from from a MYSQL view into a CSV using a bash script.

As inspiration I used this post: How to use a bash script to write to a mysql table

The strange part is that SELECT column1,column2,column3 FROM syntax works fine, but it is not practical when you have some 15 columns…

Also SELECT count(*) FROM works

However SELECT * FROM is throwing a MYSQL syntax error

#!/bin/bash

fpath=/tmp/
fname=`date +%Y%m%d-%H%M%S`.csv
savedest=\'$fpath$fname\'

echo "Saving into"$savedest

params="-u root -p mydb"
 s1="SELECT * FROM flat_view INTO OUTFILE "
s2=" FIELDS TERMINATED BY ','"
s3=" ENCLOSED BY '\"'"
s4=" LINES TERMINATED BY '\\n'"
selectend=";"

echo $s1$savedest$s2$s3$s4$selectend | mysql $params

I am thinking I have not escaped something properly.

PS. This is Centos 5.8 and mysql Ver 14.12 Distrib 5.0.95

  • 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. Editorial Team
    Editorial Team
    2026-06-15T04:46:11+00:00Added an answer on June 15, 2026 at 4:46 am

    While typing up the question I decided to try one more thing for laughs:

    s1="SELECT flat_view.* FROM flat_view INTO OUTFILE "
    

    and it worked!

    I found a reference to a possible ambiguity of SELECT * reading MySQL documentation: http://dev.mysql.com/doc/refman/5.5/en/select.html

    Still, it is strange that SELECT * FROM worked fine from mysql command line, but not from a bash script.

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

Sidebar

Related Questions

I'm trying to restore a Mysql dump from a Java app. I'm using this
I am trying to restore a MySQL database from a dump file in my
I am trying to output POST-data that I send from an android phone, however
I am trying to send data from PHP to a bash script and then
I'm using Coldfusion8 and MySQL and am trying to insert into a table. However
I am trying to access hive table and dump the result back into text
I'm trying to make a dump of a MySQL table on the server and
I am trying to parse some data from external site to local script. Local
I'm trying to extract all words from a string into an array, but i
Just using a SELECT in my MySQL statement, trying to get a column. $last_visit

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.