Dropping tables in MySQL

This is a discussion on "Dropping tables in MySQL" within the Databases section. This forum, and the thread "Dropping tables in MySQL are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jul 18th, 2007, 13:14
Daniel's Avatar
Elite Veteran
Join Date: Sep 2006
Location: The Kingdom of Rabbits
Age: 21
Posts: 2,051
Blog Entries: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Daniel
Dropping tables in MySQL

If you drop a table in mysql can you reactivate it? or is it deleted?
Last Blog Entry: Assassin's Creed (Nov 22nd, 2007)
Reply With Quote

  #2 (permalink)  
Old Jul 18th, 2007, 16:37
SuperMember

SuperMember
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

As far as I am aware once a table is dropped in MySQL thats it, its gone. I have lost entire DBs simply by pressing the x in phpmyadmin.
I now back up my database before I do any work on them.
I hope someone proves me wrong as it would be useful to know.
All the best.

Pat
Reply With Quote
  #3 (permalink)  
Old Jul 18th, 2007, 17:24
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

Quote:
Originally Posted by DanDoughty View Post
If you drop a table in mysql can you reactivate it? or is it deleted?
You can restore it from your most recent backup
Reply With Quote
  #4 (permalink)  
Old Jul 18th, 2007, 21:05
SuperMember

SuperMember
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

I believe it does destroy the database though. I don't mean to hijack this thread or anything but obviously backing up your DB's is V. important and being new to MySQL and PHP I was just wondering how people go about this. What's the best way?

This is coming from an man who lost 400gb of data off a computer last thursday and lost another 150gb yesterday (hard drives died on me but 2 in a week is bad luck) and has paid a small fortune (well not that much but I shouldn't have lost the data in the first place) to get it retrieved. So lets just say my backup policy isn't a strict one nor is it flawless (it doesn't exist).


Pete.
Reply With Quote
  #5 (permalink)  
Old Jul 18th, 2007, 21:26
SuperMember

SuperMember
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

I am assuming you use phpmyadmin to add or remove from your db, the backup is quite easy. providing you have stable HD'S (LOL).if you export your database to a text file in phpmyadmin you then have a full backup of your db which can then be imported back into your db. you may have to dump the existing tables in your db to allow the import.
I have done this many times, I also keep a copy of my latest db on another computer incase things go wrong.
I hope this makes sense.

Pat
Reply With Quote
  #6 (permalink)  
Old Jul 18th, 2007, 21:36
SuperMember

SuperMember
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

That's cool. I didn't realise it was that easy. Is there nay way I could do this automatically every 24 hours or so or would this be more complex? Obviously if its being updated by me occasionally like say a basic info site then it would be fine but for a blog or a forum you would need regular backups. I'd simply forget.

Pete.
Reply With Quote
  #7 (permalink)  
Old Jul 18th, 2007, 21:49
SuperMember

SuperMember
Join Date: Jun 2007
Location: uk
Posts: 459
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

I am sure this is possible but the answer probably exists with someone like grahame or another db expert. I think sessions may be your answer but I am not sure
Reply With Quote
  #8 (permalink)  
Old Jul 18th, 2007, 22:00
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

Quote:
Is there nay way I could do this automatically every 24 hours or so or would this be more complex? Obviously if its being updated by me occasionally like say a basic info site then it would be fine but for a blog or a forum you would need regular backups. I'd simply forget.
mysqldump + cron.
I suppose you could do the backup using PHP's exec() function if you really wanted.
Reply With Quote
  #9 (permalink)  
Old Jul 18th, 2007, 22:00
Daniel's Avatar
Elite Veteran
Join Date: Sep 2006
Location: The Kingdom of Rabbits
Age: 21
Posts: 2,051
Blog Entries: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Daniel
Re: Dropping tables in MySQL

Was in the wrong database anyway so it didnt really matter lol
Last Blog Entry: Assassin's Creed (Nov 22nd, 2007)
Reply With Quote
  #10 (permalink)  
Old Jul 18th, 2007, 22:53
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

Grrrrrrrrrr.
I wrote a PHP script to backup the database when executed by cron, then I went to check mysqldump syntaxes and I hit the [insert expletive here] "Google Earth" logo on the Google toolbar instead of the tab and I lost the post.

So now I am writing it again and my relationship with the Google toolbar has gone very much downhill.

Formatting didn't work inside the PHP tags, but it should give an idea of where things need changed.
PHP: Select all

<?php
$time 
time();
$command "/usr/bin/mysqldump --quick -u [i]username[/i] -p [i]password[/i] [i]db_name[/i] | gzip > ~/backups/$time.mysql.gz";
/*
/usr/bin/mysqldump   is the path to the mysqldump program
--quick   stops the program from loading the whole result into memory
-u [i]username[/i]   is the mysql username
-p [i]password[/i]   is the mysql password
[i]db_name[/i]    is the name of the database
| gzip    is an example of piping. The output from the bit before the pipe is passed to the 
command after the pipe. i.e. gzip....this compresses the result
> ~/backups/$time.mysql.gz    saves the file with a unique filename (Unix timestamp)
*/


exec($command);

?>
I would have posted the cron code here, but the webforumz servers throws a 406 Not Acceptable error at me.
The only other time I have got this message here is when I modify HTTP headers.

So if anyone actually cares, I can post it to pastebin or similar.


This requires you to have pretty much control over the server. e.g. Owning it.

I got the mysqldump syntax stuff here (Quite useful if you are doing this).

I can't test the PHP script since I don't have any physical access to a server with a database.

Last edited by balaclave; Jul 18th, 2007 at 23:13.
Reply With Quote
  #11 (permalink)  
Old Jul 18th, 2007, 23:51
SuperMember

SuperMember
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

Oh, so its nice and simple then . Being completely useless at this sort of thing, I'll probably leave it for now. It was mainly out of interest though it is something I will have to learn how to do at some point. I have become deeply concerned about every last scrap of info I ever save anywhere and in a blog/ forum situation the it would be very useful. Imagine an e-commerce site didn't backup their DBs, it would be a nightmare. I am learning php so I can really take advantage of it (I am starting with a blog and will build up to a MySpace beater in the end). Is the alternative to manually save the backup the DBs.

By the way, balaclave, thank you. You are a great asset, you put in so much time and effort I don't know what I'd do without you. I happen to know that the rep points work, after a fashion (open in new tab), so you can have some from me!

Pete.
Reply With Quote
  #12 (permalink)  
Old Jul 19th, 2007, 07:33
sannbe's Avatar
SuperMember

SuperMember
Join Date: Dec 2006
Location: San Francisco
Age: 57
Posts: 1,567
Blog Entries: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

My import/ export to phpadmin looks like a freeway. I figured that one out on my own after loosing a very large important database when I accidently hit EMPTY...at least I still had my column headings....
Last Blog Entry: More Sara Blogging (Nov 29th, 2007)
Reply With Quote
  #13 (permalink)  
Old Jul 19th, 2007, 12:58
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Dropping tables in MySQL

Quote:
I figured that one out on my own after loosing a very large important database when I accidently hit EMPTY...at least I still had my column headings....
Gutted!
phpMyAdmin is one of those annoying programs where it asks for confirmation using javascript, so I'd imagine if you had it turned off, then I suppose you're screwed.
Another problem with the javascript confirmations is when using prefretch tools like Google's web accelerator...it goes and tries to fetch pages before you visit them, e.g. the links to dump the database, but ignores the javascript warnings.


Sometimes if I try to manually export a database in phpMyAdmin, exporting to a filetype like gzip causes it to crash if the file is quite big.

The only option which works in this situation is export to text, which is annoying because it really exports it into a textarea, not a txt file.
When I had to do this I copied and pasted chunks from the textarea to notepad (because my computer couldn't handle copying and pasting 15mb at once), which took a long time.

However it just hit me while writing this post that a better way to do it would be to save the page where the db export is loaded into a textarea, and then remove the extraneous HTML from the file.
Or choose a host where phpMyAdmin works properly.

@pete:
Thanks

Last edited by balaclave; Jul 19th, 2007 at 13:06.
Reply With Quote
Reply

Tags
mysql

« wamp | mysql error »
Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] PHP Creat tables in MySQL Emzi PHP Forum 4 Jan 21st, 2008 12:41
Displaying MySQL database tables on a page vandiermen PHP Forum 3 Jun 30th, 2007 21:58
Country, postcode etc - mysql tables jimz Databases 2 Jan 30th, 2007 17:02
Help with Button dropping slice! gnarlysurfer JavaScript Forum 6 Jun 22nd, 2006 21:18
Just dropping in to say hello New Zeal Introduce Yourself 8 Dec 29th, 2005 05:16


All times are GMT. The time now is 19:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43