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
  #22  
Old 05-07-2006, 06:53 PM
Bubble #5 Bubble #5 is offline
 
Join Date: Apr 2005
Posts: 984
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lil Ripsta
Whoa that's pretty hot. Is that a feature-already in cPanel 'cause I am always hoping for an automatic backup system for cPanel.
They don't use cPanel, they use their own scripts (called netadmin) and I must say it's the nicest (and easiest to use) control panel that we've ever seen :banana:
Reply With Quote
  #23  
Old 06-02-2006, 02:55 AM
furst furst is offline
 
Join Date: Dec 2005
Posts: 362
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm trying to move from one server to another. The server I am moving FROM doesn't have ssh access so I'll have to do it in phpmyadmin. The server I'm moving TO does not have phpmyadmin so I'll have to use the ssh method.

Can I use part 1 of the phpmyadmin tutorial and part 2 of the ssh tutorial? It's okay to combine the two like that, isn't it?
Reply With Quote
  #24  
Old 06-03-2006, 03:02 AM
Chevy II Chevy II is offline
 
Join Date: Nov 2003
Posts: 34
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi,
I'm restoring my database using phpMyAdmin and I followed step 2 in the first post when attempting to restored the db. When I do this I get the following error, does anyone know why or how to fix this?

Quote:
SQL query:

_sitedb_.sql

MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_sitedb_.sql' at line 1
Reply With Quote
  #25  
Old 06-04-2006, 04:55 AM
SixteenOhNine SixteenOhNine is offline
 
Join Date: Apr 2006
Location: Tennessee
Posts: 83
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Using SSH to backup your SQL file doens't specifically compress the database, the --opt command optimizes the database and clears the overhead on each table. While it may appear to be smaller, the database is actually the same size, without the overhead.

As for Site5, they actually do use CPanel, it is simply a skinned version of CPanel which is rebranded. They have indeed added their own features, such as FlashBack and such services, however it's easy to see they still use a rebranded version of CPanel .
Reply With Quote
  #26  
Old 06-26-2006, 04:30 AM
G_Man G_Man is offline
 
Join Date: Feb 2006
Location: Washington State
Posts: 264
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Bubble #5
Site5 has a unique feature called 'Flashback' which automatically backs up every file that is one the server. You don't have to do anything. To restore a file simply click it from a master list and it's restored :bunny:
Site5 still recommends you use phpAdmin to backup your databases though.....


Which brings me to my question for anyone who can help -

When phpAdmin asks for a filename template for the database backup file there is this message below:

Quote:
This value is interpreted using strftime, so you can use time formatting strings. Additionally the following transformations will happen: __SERVER__/server name, __DB__/database name. Other text will be kept as is.

Okay, I assume this means I can put something in the template which cause the filename to include the date/time, but I don't know what. Anyone help me with this??

Cheers.
Reply With Quote
  #27  
Old 06-26-2006, 05:35 AM
Bubble #5 Bubble #5 is offline
 
Join Date: Apr 2005
Posts: 984
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by G_Man
Site5 still recommends you use phpAdmin to backup your databases though.....
That's because Flashback doesn't back up databases yet
Reply With Quote
  #28  
Old 07-20-2006, 07:23 PM
frandy frandy is offline
 
Join Date: Mar 2006
Posts: 39
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how do you find the correct path??
Reply With Quote
  #29  
Old 09-09-2006, 11:45 AM
webgeek247 webgeek247 is offline
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 124
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My previous host had ssh access, my new host doesnt, so I used the bigdump method, which seemed to have restored the mysql file on my new database, now I cant view my forums homepage (its blank) however I can log into admin cp without a problem
Reply With Quote
  #30  
Old 09-09-2006, 07:38 PM
CBrown CBrown is offline
 
Join Date: Mar 2006
Posts: 25
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm having some issues myself...

I'm all backed up via the export function on my old server. Fine.
I have a new dedicated server. So I created the database, and user for sql.

Problems.

I don't think I'm setting up the permissions for that new user correctly... I'm using plesk to add the new database and user. Fine.

I try to restore the database via ssh, and I get:

Can't create database 'DB_Name'; database exists

Ugh... So what is the issue there? If I delete the database, and do it that way, I get the errors saying no database exists. So I feel like i'm stuck.

I know there is probably a simple answer, but I just cant find it.


Thanks in advance folks.


Carter

Ah ha.. think I found the answer...

in ssh.. on a new server... use the "-f" command to ignore the error messages.
That fixed it.

sql -f -u USERNAME -p DB_NAME < /Path_to/sql_dump_file.sql

@dj

look here:
http://www.vbulletin.com/docs/html/blank_pages
Reply With Quote
  #31  
Old 09-10-2006, 07:55 AM
webgeek247 webgeek247 is offline
 
Join Date: Mar 2006
Location: United Kingdom
Posts: 124
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by CBrown
Thanks for that CBrown, it got the homepage displaying however I'm getting the following error now on the top of my forums homepage :hurt:

Quote:
Warning: Call-time pass-by-reference has been deprecated - argument passed by value; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file. However, future versions may not support this any longer. in /websites/LinuxPackage02/xx/xx/xx/xxxxxx/public_html/forums/index.php(485) : eval()'d code on line 18
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 06:51 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.08350 seconds
  • Memory Usage 2,314KB
  • Queries Executed 25 (?)
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
  • (7)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
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)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