Transactions
In many SQL environments including MySQL, the database can be run in a state in which the database itself records all the changes that are made as you work. This is known as transactional storage, and can itself be a form of versioning.
For MySQL:
START TRANSACTION;
SELECT * FROM mn_plants
WHERE genus = 'ACER'
;
# Now make a change to the table
UPDATE mn_plants
SET code = 'ACNE'
WHERE genus = 'ACER' and species = 'NEGUNDO'
;
# note change was made
SELECT * FROM mn_plants
WHERE genus = 'ACER'
;
# whoops! this is not in concordance with USFS code
rollback;
# change is Gone after rollback!
SELECT * FROM mn_plants
WHERE genus = 'ACER'
;
MySQL has a slightly looser form of transactions than many databases - it needs to be turned on and used, rather than being automatic - but you can still “undo” if you know right away you have messed up.
MySQL Dump files
It is good practice to export MySQL to the type of human-readable SQL dump file that we started the class with.
- in MySQL Workbench, choose the “Management” tab
- Choose “Data Export”
- Select the “BeeLab” schea to export
- Uncheck any tables you do not wish to include
- Make sure the selection is for “Dump Structure and Data”
- Choose destination location
- Backup, backup, backup…