MySQL Forums
Forum List  »  CSV Storage Engine

Cron bash MySQL Query from 2 tables - export to CSV
Posted by: Kevin Mc
Date: September 13, 2013 04:07PM

I am really bad at creating MySQL queries and need some help. I need to create a bash file to be triggered by a cron job once a week - that queries two tables, grabbing data where the user IDs match in both tables, and adding the select data to a CSV export file. I would like the CSV to be comma separated. Right now the best I can get it tab separated, but that's not my current problem....

My issue in getting this query to run is my syntax (which I know is wrong as I have simply stolen snippets from various articles online). I did get each DB query to work separately (grabbing from one table with one query and another table with another query). Now I need to combine them to grab only the data I need.

Here's my current (non working) bash file:

!/bin/bash
mysql -u USERNAME --password=PASSWORD --database=xxxx_DBNAME --execute='SELECT xxxx_videotraining_user.user_id, xxxx_videotraining_user.training_title, xxxx_videotraining_user.status, xxxx_users.id, xxxx_users.name, xxxx_users.user_employer, xxxx_users.user_ss_number WHERE xxxx_videotraining_user.user_id = xxxx_users.id AND xxxx_videotraining_user.status = "Completed" AND xxxx_users.user_ss_number > "1" ORDER BY xxxx_videotraining_user.user_id LIMIT 0, 10000 AND ' -C > /home/xxxx/subs/vtc/DB_EXPORTS/xxxx_videotraining_completed.csv

I think you can see what I am trying to accomplish here - any help would be greatly appreciated!

NEXT: is there a way to email the results to a specific email address (or multiple addresses) using the bash file?

Thank you.
--Kevin

Options: ReplyQuote


Subject
Views
Written By
Posted
Cron bash MySQL Query from 2 tables - export to CSV
5795
September 13, 2013 04:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.