How to export result of a MySQL query using phpMyAdmin 3.4.3?

111,859

Solution 1

  1. Execute your sql query in the SQL tab of phpMyAdmin.

  2. After execution, scroll down the page and look for “Query results operations”

  3. Click “Export” link from the above and you will get the page to export all the results of the queries to desired format.

Solution 2

Instead of the export button at the top of the GUI, use the one at the bottom, within the "Query results operations" box. That is the one you want.

Export button

Solution 3

On some query it's not possible in a direct way.

You must write the query result to a table through the create table as syntax And then you can follow the normal export instructions: https://serverfault.com/a/300342/256884

Solution 4

You've already got the query? You can insert into a new table using another query's results

Looks like the steps you need:

  1. Create the new table with all the columns.
  2. INSERT INTO newTable (field1, field2, field3) SELECT field1, field2, field3 FROM otherTable GROUP BY field1

Adjust for your 50-line query.

Solution 5

I still needed an answer to this old question for a query from multiple tables and I came up with a good one. As others have stated, you can try the Export option under "Query results operations". As another other people noted, that does not always work and it may just give you all the rows from one table. That option did not work in my case. I also wanted something simpler than writing code to insert the results into a new table and then exporting that.

I found two easy ways to do this.

Method 1: Copy and paste

Check the "Show all" box above the results, highlight all the results, copy, and paste into a spreadsheet. That worked for me in Excel. However, the results preview truncates cell values that are too long. Therefore, this may not work for you if your cell values are long and you need the complete values.

Method 2: Create view

Under "Query results operations", there is an option to "Create view". Created views will appear below the database Tables in a new "Views" category. Views are basically persistent tables that show custom query results. Click "Create view", enter a name for the view and Go. Now you successfully use the Export option under "Query results operations" while in the View.

Share:
111,859

Related videos on Youtube

grape
Author by

grape

Updated on September 18, 2022

Comments

  • grape
    grape over 1 year
    1. I've got a 30K row table
    2. When I run a long, 50-line query on that table, a GROUP function reduces the number of rows to 7K
    3. I want to export the grouped 7K rows as a new table, or save them as a CSV

    When I attempt to export, instead of getting the grouped 7K rows, I get the old, pre-query 30K rows. What am I doing wrong, and what should I be doing?

    NOTE: I'm not a coder, so I'd really appreciate a solution that just used the phpMyAdmin GUI.

    • Bob Ortiz
      Bob Ortiz almost 8 years
      It would be very helpful to supply the SQL queries that phpMyAdmin created and used.
  • grape
    grape over 12 years
    Thanks!Let me see if I understand... (1) create newtable (2) oldtable has about 60 columns, and all are being used, so... INSERT INTO newtable * SELECT * from oldtable (3) do i place your INSERT INTO code at the end of my existing query?
  • Reece45
    Reece45 over 12 years
    You put the INSERT INTO before your query. It works just like a normal INSERT except instead of providing "VALUES (rowColumn1, rowColumn2, rowColumn3)", you're providing the results of the SELECT instead.
  • Sudipta Chatterjee
    Sudipta Chatterjee over 12 years
    I had uploaded a picture here as well - wonder where it went. P.S. - if this solved your problem, please mark it as the correct answer.
  • octern
    octern about 11 years
    Thanks! In the current interface there's yet another incorrect "export" button, right about the "query results operations" box. The screenshot is helpful.
  • Nicholas Decker
    Nicholas Decker about 10 years
    Very simple, don't know why I haven't seen it there in the past!
  • Nick Pickering
    Nick Pickering over 7 years
    If your query returns a large number of records (many pages), this is the only solution.
  • Web_Developer
    Web_Developer over 5 years
    Chosen "Export" from “Query results operations” and it shows all records from the table rather than the query result. Is there anything else to be selected ?
  • Mark Locklear
    Mark Locklear about 4 years
    @Web_Developer I agree this is misleading. In the Rows section under the "Dump all rows(s)" option, it shows all the rows in the DB rather than just the rows from the query result. However, if you click "Go" you only get the rows from the query result.