Boat Drinks  

Go Back   Boat Drinks > General > Computer and Consoles

Reply
 
Thread Tools Display Modes
Old 27-08-2009, 01:00   #1
Joe 90
Absinthe
 
Joe 90's Avatar
 
Join Date: Jan 2007
Location: Chester
Posts: 2,345
Default SSH mysql backup

Evening, I'm trying to make a backup of a databse via SSH

so, i've connected to the database;
Code:
mysql -h mysql14.streamline.net -u USERNAME -p
and then keep tryin this command but it doesn't ask for my password so obviously isn't working;
Code:
mysqldump --opt -Q -shuwarrior1 -p shuwarrior1 > /backups/backup.sql
I've never used SSH before so don't really know how to figure it out :/
__________________
360 Blog | Join GiffGaff | Twitter
Joe 90 is offline   Reply With Quote
Old 27-08-2009, 02:21   #2
Mark
Screaming Orgasm
 
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
Default

Code:
mysqldump --opt -Q -u username -p database | gzip -9 > backups/backup.sql.gz
username and database as required. Note the spaces after -u and -p. It will ask for the password.

PS - I added on compression for you. May as well do it all in one go. If you don't want that, omit the gzip part.
Mark is offline   Reply With Quote
Old 27-08-2009, 05:26   #3
Garp
Preparing more tumbleweed
 
Garp's Avatar
 
Join Date: Jun 2006
Location: Hawaii
Posts: 6,038
Default

Quote:
Originally Posted by |Show| View Post
so, i've connected to the database;
Code:
mysql -h mysql14.streamline.net -u USERNAME -p
and then keep tryin this command but it doesn't ask for my password so obviously isn't working;
Code:
mysqldump --opt -Q -shuwarrior1 -p shuwarrior1 > /backups/backup.sql
Woah back a bit.. maybe I'm misreading this. Are you runing the mysql command, and then once a mysql prompt is up running the mysqldump command? If so that'll never work, mysqldump should be run from the command line.

SSH on to the server, you should have a command prompt that ends with the "#" symbol.

From there run the mysqldump command like Mark suggested. I tend to do things slightly differently from Mark but it depends on what you're trying to do with the backup, more often than not I'm backing up databases in an environment where it's not too unusual for someone to have messed up a slave ('read only') server.

To try to be a little nicer and make the backup run at a lower priority to standard tasks it's worth prefixing it with "nice", e.g. using Mark's command:
Quote:
nice mysqldump --opt -Q -u username -p database | gzip -9 > backups/backup.sql.gz
__________________
Mal: Define "interesting"?
Wash: "Oh, God, oh, God, we're all gonna die"?
Garp is offline   Reply With Quote
Old 27-08-2009, 10:35   #4
Mark
Screaming Orgasm
 
Join Date: Jul 2006
Location: Newbury
Posts: 15,194
Default

Good spot there, except it'll probably be shared hosting, so the prompt will be '$', not '#'.

PS - Will that 'nice' actually do anything? It won't be mysqldump taking the CPU resources.
Mark is offline   Reply With Quote
Old 27-08-2009, 16:55   #5
Garp
Preparing more tumbleweed
 
Garp's Avatar
 
Join Date: Jun 2006
Location: Hawaii
Posts: 6,038
Default

Quote:
Originally Posted by Mark View Post
PS - Will that 'nice' actually do anything? It won't be mysqldump taking the CPU resources.
I think that's one that'll be debated back and forth. Depends on what the server is doing. mysqldump still does require a chunk of processing power whilst the server is working. Most often at the moment I'm dealing with all-in-one systems, full on LAMPs. Dropping the priority on mysqldump seems to help keep Apache far more responsive.
__________________
Mal: Define "interesting"?
Wash: "Oh, God, oh, God, we're all gonna die"?
Garp is offline   Reply With Quote
Old 27-08-2009, 18:56   #6
Joe 90
Absinthe
 
Joe 90's Avatar
 
Join Date: Jan 2007
Location: Chester
Posts: 2,345
Default

yeah its a shared hosting package, so I've got the SSH access on my domains, and then the mysql is on a different server.

So I assumed that the mysqldump command wouldn't be able to backup the server if its being ran from my domain because it doesn't contain anything relating to the mysql server, just a username and database name which has nothing to do with my domain :/

Was a bit confusing using documentation from my host and also vB!
__________________
360 Blog | Join GiffGaff | Twitter
Joe 90 is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 15:31.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.