Jump to content

Archived

This topic is now archived and is closed to further replies.

matd

Strange characters � in mysqldump output

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 :-)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.