PDA

View Full Version : Exporting MySQL tables to a CSV file


banjo
08-20-2006, 04:30 PM
Can anyone assist with how to export a table to a .CSV file using PHPMyAdmin on the Digitalhost server.

When I select a table, and click on Export, and fill in the appropriate parameters, it shows a field in which I need to enter a file template. What value goes in there? Is it a pre-defined template or do I just enter the filename of where I want it to be stored? Also, where does the exported file get stored and how can I access it?

Incidentally, when I try to Export using a "SELECT .. INTO OUTFILE ..." statement directly from my script, it indicates an "error 1045 - Access denied for user". If I use the "SELECT" statement without "INTO OUTFILE" to display the same table to my screen there is no problem. I suspect this means it is trying to Export the file to an area for which my database login does not have permission.

Any ideas?

digital
08-22-2006, 11:36 AM
banjo

Sounds like your trying to do this via a phpmyadmin link instead of logging into Cpanel first and then going to phpadmin.

Ensure you have a direct login, exporting to .txt or .sql files is fairly straight forward.

Login to Cpanel
Click Mysql Databases
Click the link at bottom of page [ phpMyAdmin ]

Choose the database from the list
Click EXPORT
Check the box bottom of page left side which says [ Save as file ]
Choose from the list [ sql pdf csv etc etc ]
Click GO right side of page down the bottom

Will save to your computer.

banjo
08-24-2006, 10:03 PM
Thanks for the advice. I was actually doing it via Cpanel and phpMyAdmin as per your description, but it wasn't working. Someone submitted a trouble ticket on my behalf and the guys at Digitalhost fixed it, and I have been trying to find out if they made any changes to my account setup to fix it, for future reference. I can now export fine via phpMyAdmin using the same procedure I was using before.

I am now trying to find out how to export using a PHP script into MySQL server. Apparently, according to the manual, you can only use "SELECT .. INTO OUTFILE ..." statement to export to the local MySQL server.
The manual says I should use something like mysql -e "SELECT ... > file_name" to generate the output file on a client host.

I am still working on this.