Yesterday, I was working on a shell script to do some moderately complex table inserts into a MySQL database. Naturally, I maintained an open mysql shell window to run describe commands, selectively query and delete test lines between test cycles.
Yes, it was in a live, production database.
At the moment when I finished my encoding, I asked a colleague to review my work before running a script to process records in a batch. We went around everything, he agreed that he looked right at him, and I shot from a script. No problems.
Then I went back to my live shell, pulled out a line from the history, changed the where clause to look at the inserts received, and press [Enter] ...
... Unfortunately, I did not watch the whole team that I edited! It was a delete , not a select .
by email Oh.
Okay, so I know that I could configure another DBMS server, restore the dump of this database and complete all my tests. We all know that it would be safer and more disciplined. We also all know that sometimes it’s more advisable to work in a live store. (In this case, the risks are slightly lower than you might expect ... the database in question is used for batch processing, and we were able to restore the backup, which was only 20 minutes within 10 minutes after delete ).
However, this begs the question: is there any option (or patch) for the mysql client shell that will be read-only? Is there any way to change what he stores in his interactive story? (Something that would mark delete and drop table and similarly “dangerous” statements as “a request to check before re-executing?” Does the mysql client have something similar to the bash HISTIGNORE function?
What is a safer way to do this kind of work (without working on a completely separate copy of the database)?