Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > Programming Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Backup/restore using phpMyAdmin/SSH
Snake's Avatar
Snake
Join Date: Mar 2005
Posts: 3,832

 

Cleveland, OH
Show Printable Version Email this Page Subscription
Snake Snake is offline 02-01-2006, 10:00 PM

Backing Up & Restoring a MySQL Database using phpMyAdmin / SSH
================================================== =====

This is just a short mini-tutorial explaining how to backup parts of the mySQL database using phpMyAdmin and also via SSH (Secure Shell) access. This tutorial should be of use to most people, as it's an important part of any website/forum maintenance.

So, let's get started...

Step 1 - Backing up using phpMyAdmin

Note: Most good hosts provide phpMyAdmin (mySQL administration). If you do not know where it is or even if it exists on your server, just get in touch with your host.
  1. Login to phpMyAdmin.
  2. Select the database you wish to use.
  3. On the navigation bar on the top, select "Export" (besides SQL, Structure, Search, Query... etc.)
  4. You should now be presented with a nifty little page which shows all the tables in the database, SQL Options and Save Types. *
  5. To backup the whole database, click "Select All" under the list of tables in the page.
  6. To backup a selected few, just hold down CTRL on your keyboard and select the tables you wish to backup (release the key when all selecting is done).
  7. SQL Options can be left as default, but I suggest ticking the "Add DROP TABLE" option as if you are restoring a backup on a database that already exists and has the table in it - you will get a lot of errors! This way, by ticking the "Add DROP TABLE" option you will avoid the errors. For more information on the options just click the little "?" icon after SQL Options.
  8. If you want to save the backup as a file (recommended) then tick "Save as file" - Leave file name as is or edit for your needs. Select "gzipped" as compression. Now click "Go". If asked, choose "Save to disk" and save it wherever on your computer (it may take sometime depending on the size).
  9. If you want to show the whole backup SQL on your browser window, don't tick "Save as file" - once you have selected the tables you wish to backup (explained in step 5/6) click "Go". The page will now change and should show the SQL information (it may take sometime depending on the size). Copy and paste it to a text file or do whatever you want with it!
Note: Yes, the tables of the database will be shown to the far left in a frame, but they will also be displayed in a different form on this new page to the right in phpMyAdmin.

Congratulations! You have successfully backed up your database / selected tables!

Step 2 - Restoring your database using phpMyAdmin

Note: Most good hosts provide phpMyAdmin (mySQL Administration). If you do not know where it is or even if it exists on your server, just get in touch with your host.
  1. Login to phpMyAdmin.
  2. Select the database you wish to use.
  3. On the navigation bar on the top select "SQL" (besides Export, Structure, Search, Query... etc.)
  4. You should now be presented with a little page which allows you to run SQL query/queries on the database, either by inputting the query/queries to the input box or by locating a text file on your computer.
  5. You now have 2 options: 1) Paste the SQL which you backed up earlier in the "Input Box" and click "Go" or 2) If you saved the file on your PC then use the option below the first one; Click Browse > Locate the File > Click "Go". (Note: Most servers set a "Max File Size" for uploading the SQL, the size appears beside the Browse button.)
  6. It may take sometime for the file to be uploaded and fully run, so give it a chance. Once it worked, it will bring you back to the same page and should confirm if all went well "Your SQL-query has been executed successfully: The content of your file has been inserted."
Congratulations! If all went well, you have successfully restored your backed up database!

Step 3 - Backing up using SSH

Note: Some hosts do not offer SSH access, I suggest contacting your host and asking him/her if SSH access is enabled and if so the details. A good program to use for connecting via SSH is PuTTY (Get it at: http://www.chiark.greenend.org.uk/~sgtatham/putty/). Don't know how to use it? Search on Google for a tutorial.
  1. Connect to your host via SSH, login and run: mysqldump --opt -u user -p dbname > {path}/backup.sql
  2. You will be asked to type out your password once you run that command, do so and click enter. It may take some time for it to respond, but once completed you should be brought back to where you started (bash/command line).
Congratulations! You successfully backed up your database using SSH.

Step 4 - Restoring using SSH

Note: Some hosts do not offer SSH access, I suggest contacting your host and asking him/her if SSH access is enabled and if so the details. A good program to use for connecting via SSH is PuTTY (Get it at: http://www.chiark.greenend.org.uk/~sgtatham/putty/). Don't know how to use it? Search on Google for a tutorial.
  1. Connect to your host via SSH, login & run: mysql -u user -p dbname < {path}/backup.sql
  2. You will be asked to type out your password once you run that command, do so and click enter. It may take some time for it to respond, but once completed you should be brought back to where you started (bash/command line).
Congratulations! You have successfully restored your database using SSH.

That's basically it I think, I believe I have covered everything? Anything I missed? Comments or suggestions? Just let me know! Hope this tutorial was as useful to you as it is to me.

Thanks,
-Snake
www.metalgearforums.com
Reply With Quote
  #2  
Old 02-03-2006, 01:12 AM
RFViet RFViet is offline
 
Join Date: Jan 2006
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My server just allows me to upload file size = 8Mb max. My sql file = 200 Mb. How do i restore ???
Reply With Quote
  #3  
Old 02-03-2006, 03:15 AM
The Chief's Avatar
The Chief The Chief is offline
 
Join Date: Aug 2005
Location: Montreal
Posts: 1,037
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by RFViet
My server just allows me to upload file size = 8Mb max. My sql file = 200 Mb. How do i restore ???
You will have to use SSH, or ask your host to raise the max limit...
Reply With Quote
  #4  
Old 02-04-2006, 11:17 AM
Snake's Avatar
Snake Snake is offline
 
Join Date: Mar 2005
Location: Cleveland, OH
Posts: 3,832
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Or you can split every tables with the maximum of 8MB in each file... That's the best way to go for!
Reply With Quote
  #5  
Old 02-07-2006, 08:48 AM
Rhoads Rhoads is offline
 
Join Date: Dec 2004
Location: Holland
Posts: 211
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I tried but i get a error:

Got error: 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) when trying to connect -/bin/bash-2.05b$

Whats the problem, i use the command from your post, with my user and database name.
Reply With Quote
  #6  
Old 02-07-2006, 01:37 PM
Snake's Avatar
Snake Snake is offline
 
Join Date: Mar 2005
Location: Cleveland, OH
Posts: 3,832
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmm that's weird. I'm not sure about that error because it has nothing to do with my tutorial. And I bet you have done something wrong while attempting to restore your forums.
Reply With Quote
  #7  
Old 02-08-2006, 04:15 PM
RFViet RFViet is offline
 
Join Date: Jan 2006
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Aftermath
Or you can split every tables with the maximum of 8MB in each file... That's the best way to go for!
Yeah , that's the way i want . How to do that ???
Reply With Quote
  #8  
Old 02-10-2006, 04:27 PM
Logan70 Logan70 is offline
 
Join Date: Nov 2003
Posts: 49
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can also try and use:

http://www.ozerov.de/bigdump.php

It will allow for large dumps to be staggered, making it look like smaller pieces.
Reply With Quote
  #9  
Old 02-12-2006, 02:04 AM
Ramsesx's Avatar
Ramsesx Ramsesx is offline
 
Join Date: Aug 2005
Location: Southern Germany
Posts: 512
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I made it as described but my db file is only 1kb after downloading?
Reply With Quote
  #10  
Old 02-20-2006, 05:07 PM
sinaluna sinaluna is offline
 
Join Date: Feb 2005
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Should you close your board before backing up?

Thanks!
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. The time now is 01:30 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.07620 seconds
  • Memory Usage 2,296KB
  • Queries Executed 23 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete