WebFaction
Community site: login faq

I'm trying to export my MySQL database to a CSV. The command I'm using is:

mysqldump -u testdb -p -T ~/db/ testdb --fields-enclosed-by=\" --fields-terminated-by=,

The folder and write file (do I need to specify one?) permissions are both 755. The response I get is

mysqldump: Got error: 1045: Access denied for user 'testdb'@'localhost' (using password: YES) when executing 'SELECT INTO OUTFILE'

I've got so little experience with MySQL, so I'm lost. Any tips? Thanks.

asked 11 Feb '12, 15:17

atonparker
111
accept rate: 0%


This won't work since it requires special privileges which can't be granted to normal users.
So, the best way to dump the file as csv is to use phpmyadmin's export functionality.

permanent link

answered 11 Feb '12, 16:12

timg ♦♦
1.3k4
accept rate: 30%

This may be the same reason for the "access denied" error for this:

SELECT id, first_name
INTO OUTFILE 'names.tab' FIELDS TERMINATED BY 't' LINES TERMINATED BY 'n'
FROM names;

ERROR 1045 (28000) at line 1: Access denied for user 'foo_bar'@'localhost' (using password: YES)

It is possible to do this successfully using PHP:

$ vi getNames.php  
# Type the follwing into the file.    
<?php

$dbConn = new mysqli("127.0.0.1", "my_name", "my\_password", "my\_database");

$names = $dbConn->query("SELECT id, first_name FROM names;");

// Open a file for the delimited records.
$outer = fopen("names.tab", "w");

// For each row.
while ( $row = $names->fetch_row() ) {
  // Compose a line with tabs between fields.
  $lineOut = implode("\t", $row) . "\n";
  // Write the line to the file.
  fwrite($outer, $lineOut);
}

fclose($outer);

exit();
?>

$ php -f getNames.php
permanent link

answered 01 Jul '12, 00:15

flathat
11
accept rate: 0%

I ran into a problem using PHPMyAdmin for a large CSV export where my mysql connection kept getting cut because the download didn't finish in time.

I solved it by accessing PHPMyAdmin using lynx (text based browser) from my shell on the same webfaction server.

permanent link

answered 18 Mar '13, 13:24

lacto
1
accept rate: 0%

why not simply use a tool like mysqldumper?

permanent link

answered 19 Mar '13, 10:46

Clooner
51512
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×168
×6
×2

question asked: 11 Feb '12, 15:17

question was seen: 5,069 times

last updated: 19 Mar '13, 10:46

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM