Solved

Exports Multiple MySQL Tables To CSV File

Posted on 2011-03-22
2
564 Views
Last Modified: 2012-05-11
I've found these queries...

http://www.electrictoolbox.com/mysql-export-data-csv/

http://ariejan.net/2008/11/27/export-csv-directly-from-mysql/

So I'm trying to use left join etc to build a query to export multiple tables.

What I need to state every column from every table with the SELECT rather than using select all * ?

Just I'm having some issues getting it working and want to clear some things up so I'm not on an impossible path.

Thanks for your help
0
Comment
Question by:Ryan Bayne
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
tygrus2 earned 125 total points
ID: 35196276
If you join tables then the common index fields will be repeated & renamed for each occurance. Use the tablename.fieldname references to explicitly list the fields to SELECT.

eg.
SELECT Order.OrderID, OrderLine.ProductID, OrderLine.Qty
INTO OUTFILE '/tmp/orderitems.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM Order LEFT JOIN OrderLine ON Order.OrderID=OrderLine.OrderID

Open in new window

Example is a bad choice for LEFT join but you get the idea.
0
 
LVL 2

Author Comment

by:Ryan Bayne
ID: 35197574
Yes so they would that had not entered my mind yet. This is for a Wordpress plugin. So I need to provide the user with a way to select the tables they want to export plus select the columns.

The problem I'm having must be syntax then because I've tried something like what your suggesting. At least I know I was on the right path that is all I wanted really, will just dump and execute some queries in the MySQL gui.

I must remember to check the users input for any duplicate index selections.

Thanks for clearing this up
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Insert values are dynamic 11 70
How to extract database info from current month and year 7 45
Delete image(s) associated with record(s) 16 46
php hashing methods 3 50
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question