Jump to content


Photo

Strange characters  in mysqldump output


  • Please log in to reply
8 replies to this topic

#1 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 30 April 2003 - 11:57 AM

Hi,

I\'ve written a backup script which saves the output from a mysqldump and then prompts the uers to save the file. I have this working perfectly on my test server which is running apache on windows xp. But on the live server which is linux based the contents of the saved mysqldump are different.

I get these characters in the file :-



The mysqldump i run here is fine and formatted correctly when i look at it in notepad and i can import it into mysql using phpmyadmin with no problems.

But when i look at the version i download from the live server it has  in it and the formatting is all over the place and i get errors if i try and import it in phpmyadmin.

I\'m sure i have set the correct mime-type and the headers are correct too.

Any ideas why?

Any help would be grealty appreciated :D

#2 barbatruc

barbatruc
  • Members
  • PipPip
  • Member
  • 28 posts
  • LocationMontreal, Quebec, Canada

Posted 30 April 2003 - 12:07 PM

I had the same problem and discovered that it was a problem with carriage returns ® against newline (n). I don\'t remember how I did the fix but this may help you if you can tell us if the special characters are replacing the newline characters.

JP.
Unfortunately, PHP \'empowered every moron with a copy of Windows notepad to be \"web programmers\". (...) Give PHP a real INFRASTRUCTURE. Use PEAR!!!\'

#3 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 30 April 2003 - 12:14 PM

Whoa! that was quick! :-)

Well, heres a sample of the dump :-

`nALTER TABLE admin DISABLE KEYS */;  -- -- Dumping data for table \'admin\';   -- --

thats the first line of the code, it does seem to be a carriage return problem as when i pasted that line above it appeared as:-

`nALTER TABLE admin DISABLE KEYS */;

--
-- Dumping data for table \'admin\'
--

Wonder why it would be different or changes characters when the same script running locally here works perfectly.

Would it be a case of converting some characters after the dump has run then?

#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 30 April 2003 - 04:08 PM

what are you viewing the file in? some viewers do not support both windows and unix line endings. www.textpad.com is very basic, free, and can read and write either format.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 30 April 2003 - 05:50 PM

i was just using Notepad which i thought would show the bare file and ignore any formatting chars.

I\'ll try and look at it in textpad...

Still leaves the problem that i can backup and restore a mysql database in windows but can\'t backup a mysql database in Linux and restore it on a Windows platform.

Will i need to convert the line endings or somthing?

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 01 May 2003 - 12:27 AM

when saving a file, textpad allows you to choose whether the line endings should be windows or unix. code-wise... there is a unix script to do this but it has escaped me at the moment... you should also be able to parse it in php.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 01 May 2003 - 01:53 AM

mysqldump --opt -c -hlocalhost -u$user -p$password $database | unix2dos | gzip > \" . $backup_dir . \'/\' . $backup_file

By piping to unix2dos before gzip it converts all unix chars to dos / windows ones :-)

#8 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 01 May 2003 - 05:14 AM

that\'s it! :D
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#9 matd

matd
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationUK

Posted 01 May 2003 - 12:44 PM

You wouldnt happen to know how i can terminate output to the header i\'ve set that allows me to save the dump to file would you?

I have an index.php which has a button for backup. When backup is clicked it forwards the browser to backup.php where i set the header information for file saving and then echo the file.

The only thing is, after the file has been saved i\'d like to put a link on that page to direct them back to another page, but as the header has been set it just gets put in with the file being saved.

Is there someway of doing :-

header(\'Content-Disposition: attachment; filename=\"\'. $saveas_filename . \'\"\');
header(\'Cache-Control: must-revalidate, post-check=0, pre-check=0\');
header(\'Pragma: public\');

echo $dump_buffer;

<terminate output to file>

<continue with php and html for page content displayed to browser>

Help as always, is very much appreciated :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users