...
After starting a connection to the database from the command-line you should ALWAYS run:
Code Block | ||
---|---|---|
| ||
SET autocommit=0; |
By default any changes you make to the database cannot be reverted because MySQL automatically commits all changes immediately. By setting autocommit=0 you can rollback any mistakes you make. If you make a mistake you can always undo your command with:
Code Block | ||
---|---|---|
| ||
ROLLBACK; |
...
Whenever you want to make changes you should use this construct:
Code Block | ||
---|---|---|
| ||
START TRANSACTION; |
...
(UPDATE, INSERT, etc.) |
...
COMMIT; |
...
If you make a mistake when you run your (UPDATE, INSERT, etc.) command you can use ROLLBACK to undo changes back to the START TRANSACTION statement.
...