Re: Disaster with dash on mysql cli interface

2006-06-21 Thread Barry

Kevin Old schrieb:

Hello everyone,

I had a horrible thing happen to me this morning and wanted to make it
known to the community.

I needed to delete a record from a very large table (yes, it was
backed up) and like the cli interface of mysql.  I ran this query:

delete from tablename where id - 12345;

Notice that I accidentally hit the dash (-) instead of the equal (=).
It proved to be disasterous as it deleted all the records from that
table.

Lucky for me I had a backup from last night and not too many records
were added since then and I was able to restore.

For the record, I am aware of the select before delete method, but
didn't use it in this one instance and it meant a few hours restoring
data.

Just wanted to throw this out and see if others had possible solutions
for working with the mysql cli interface for maybe setting up rules
for it to cancel a query if it contains a certain character (like the
dash).  Fat chance there is, but I thought I'd ask.

Hope this helps someone,
Kevin


On this one use LIMIT.
If you want to delete specific rows alway use LIMIT.

even if you f**k up you just have deleted one row.

If you are luck it is an old one and easy restoreable.

Barry

--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Disaster with dash on mysql cli interface

2006-06-21 Thread Kevin Old

On 6/21/06, Barry [EMAIL PROTECTED] wrote:

Kevin Old schrieb:
 Hello everyone,

 I had a horrible thing happen to me this morning and wanted to make it
 known to the community.

 I needed to delete a record from a very large table (yes, it was
 backed up) and like the cli interface of mysql.  I ran this query:

 delete from tablename where id - 12345;

 Notice that I accidentally hit the dash (-) instead of the equal (=).
 It proved to be disasterous as it deleted all the records from that
 table.

 Lucky for me I had a backup from last night and not too many records
 were added since then and I was able to restore.

 For the record, I am aware of the select before delete method, but
 didn't use it in this one instance and it meant a few hours restoring
 data.

 Just wanted to throw this out and see if others had possible solutions
 for working with the mysql cli interface for maybe setting up rules
 for it to cancel a query if it contains a certain character (like the
 dash).  Fat chance there is, but I thought I'd ask.

 Hope this helps someone,
 Kevin

On this one use LIMIT.
If you want to delete specific rows alway use LIMIT.

even if you f**k up you just have deleted one row.

If you are luck it is an old one and easy restoreable.



Hi Barry,

So if I understand you correctly, I'd do the following:

delete from tablename where id - 12345 limit 1;

Is that correct?
--
Kevin Old
[EMAIL PROTECTED]

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Disaster with dash on mysql cli interface

2006-06-21 Thread Harrison Fisk

Hi,

On Jun 21, 2006, at 12:24 PM, Kevin Old wrote:


On 6/21/06, Barry [EMAIL PROTECTED] wrote:

Kevin Old schrieb:
 Hello everyone,

 I had a horrible thing happen to me this morning and wanted to  
make it

 known to the community.

 I needed to delete a record from a very large table (yes, it was
 backed up) and like the cli interface of mysql.  I ran this query:

 delete from tablename where id - 12345;

 Notice that I accidentally hit the dash (-) instead of the equal  
(=).

 It proved to be disasterous as it deleted all the records from that
 table.

 Lucky for me I had a backup from last night and not too many  
records

 were added since then and I was able to restore.

 For the record, I am aware of the select before delete method,  
but
 didn't use it in this one instance and it meant a few hours  
restoring

 data.

 Just wanted to throw this out and see if others had possible  
solutions
 for working with the mysql cli interface for maybe setting up  
rules
 for it to cancel a query if it contains a certain character  
(like the

 dash).  Fat chance there is, but I thought I'd ask.

 Hope this helps someone,
 Kevin

On this one use LIMIT.
If you want to delete specific rows alway use LIMIT.

even if you f**k up you just have deleted one row.

If you are luck it is an old one and easy restoreable.



Hi Barry,

So if I understand you correctly, I'd do the following:

delete from tablename where id - 12345 limit 1;

Is that correct?


That still will delete one row, so you still might need a backup to  
get back that row.


Another option you might want to look into is using the --safe- 
updates option to the command line client.  This will prevent you  
from doing DELETEs and UPDATEs that don't use an index properly.  For  
example, in your case deleting the entire table would have been  
prevented, whereas the correct id = 12345 would be allowed (assuming  
id is the PK or index).  I generally always use that option on a  
production machine.


It does a few other things as well (LIMIT 1000, max_join_size), so  
make sure you check it out before using it.  It used to be called --i- 
am-a-dummy mode (that option works too), so you might see it referred  
to as that in some places.


http://dev.mysql.com/doc/refman/5.0/en/safe-updates.html

Regards,

Harrison

--
Harrison C. Fisk, Trainer and Consultant
MySQL AB, www.mysql.com

Get a jumpstart on MySQL Cluster -- http://www.mysql.com/consulting/ 
packaged/cluster.html




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Disaster with dash on mysql cli interface

2006-06-21 Thread Andrew Nelson
On Wed, 21 Jun 2006 11:12:40 -0400, Kevin Old wrote:

 Hello everyone,
 
 I had a horrible thing happen to me this morning and wanted to make it
 known to the community.
 
 I needed to delete a record from a very large table (yes, it was
 backed up) and like the cli interface of mysql.  I ran this query:
 
 delete from tablename where id - 12345;
 
 Notice that I accidentally hit the dash (-) instead of the equal (=).
 It proved to be disasterous as it deleted all the records from that
 table.
 
 Lucky for me I had a backup from last night and not too many records
 were added since then and I was able to restore.
 
 For the record, I am aware of the select before delete method, but
 didn't use it in this one instance and it meant a few hours restoring
 data.
 
 Just wanted to throw this out and see if others had possible solutions
 for working with the mysql cli interface for maybe setting up rules
 for it to cancel a query if it contains a certain character (like the
 dash).  Fat chance there is, but I thought I'd ask.
 
 Hope this helps someone,
 Kevin
 -- 
 Kevin Old
 [EMAIL PROTECTED]

Doesn't mysql have transactions?  If it does you could just start a
transaction before you do anything.  This is what I do with PostgreSQL. 
As I recal oracle's sqlplus does this by default.

begin;  -- or something

-- do some stuff

-- if you did something dumb

rollback; -- or something

-- otherwise

commit; -- or something






-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Disaster with dash on mysql cli interface

2006-06-21 Thread Brendan Bouffler
This sounds awfully like doing an rm -rf somefile. * (with an accidental space 
in between the . and the *).

Most unix/linux geeks I know (including myself) only ever do this once.

Humans like to learn the hard way, it seems :-)

-- boof

On Thursday 22 June 2006 03:24, Harrison Fisk wrote:
 Hi,

 On Jun 21, 2006, at 12:24 PM, Kevin Old wrote:
  On 6/21/06, Barry [EMAIL PROTECTED] wrote:
  Kevin Old schrieb:
   Hello everyone,
  
   I had a horrible thing happen to me this morning and wanted to
 
  make it
 
   known to the community.
  
   I needed to delete a record from a very large table (yes, it was
   backed up) and like the cli interface of mysql.  I ran this query:
  
   delete from tablename where id - 12345;
  
   Notice that I accidentally hit the dash (-) instead of the equal
 
  (=).
 
   It proved to be disasterous as it deleted all the records from that
   table.
  
   Lucky for me I had a backup from last night and not too many
 
  records
 
   were added since then and I was able to restore.
  
   For the record, I am aware of the select before delete method,
 
  but
 
   didn't use it in this one instance and it meant a few hours
 
  restoring
 
   data.
  
   Just wanted to throw this out and see if others had possible
 
  solutions
 
   for working with the mysql cli interface for maybe setting up
 
  rules
 
   for it to cancel a query if it contains a certain character
 
  (like the
 
   dash).  Fat chance there is, but I thought I'd ask.
  
   Hope this helps someone,
   Kevin
 
  On this one use LIMIT.
  If you want to delete specific rows alway use LIMIT.
 
  even if you f**k up you just have deleted one row.
 
  If you are luck it is an old one and easy restoreable.
 
  Hi Barry,
 
  So if I understand you correctly, I'd do the following:
 
  delete from tablename where id - 12345 limit 1;
 
  Is that correct?

 That still will delete one row, so you still might need a backup to
 get back that row.

 Another option you might want to look into is using the --safe-
 updates option to the command line client.  This will prevent you
 from doing DELETEs and UPDATEs that don't use an index properly.  For
 example, in your case deleting the entire table would have been
 prevented, whereas the correct id = 12345 would be allowed (assuming
 id is the PK or index).  I generally always use that option on a
 production machine.

 It does a few other things as well (LIMIT 1000, max_join_size), so
 make sure you check it out before using it.  It used to be called --i-
 am-a-dummy mode (that option works too), so you might see it referred
 to as that in some places.

 http://dev.mysql.com/doc/refman/5.0/en/safe-updates.html

 Regards,

 Harrison

 --
 Harrison C. Fisk, Trainer and Consultant
 MySQL AB, www.mysql.com

 Get a jumpstart on MySQL Cluster -- http://www.mysql.com/consulting/
 packaged/cluster.html

-- 
brendan bouffler
Architect, HPC  New Technology
APJ ESS Competency Lab
x: Sydney, Australia, v: +61 404 097 837 mtb: 2003 Tassajara

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]