-
Set up a "read-only" user in addition to your administrative user and use that by default unless you actually need to make changes on production servers.
-
Disable autocommit, or use explicit transactions so you can rollback mistakes. (Beware of implicit commits)
-
To avoid
UPDATEwithoutWHEREyou can enablesql_safe_updates. Some clients have similar options. -
Get into the habit of running a SELECT query before running an UPDATE to check which (and how many) records you've selected.
-
Use color schemes to differentiate between hosts. Many terminal clients and SQL clients have the ability to set / change the color scheme.
-
Changing the prompt (PS1 in bash, or the mysql cli prompt option)
-
Minimize the need for accessing the production database directly:
- Use migrations when making production database updates whenever possible (in addition to passing the queries through CI, this means you keep a record of what changes were made and when).
- If there's things you commonly query, turn them into a "developer tool" page in your application (obviously with access restricted to developers).
Last active
October 7, 2025 12:49
-
-
Save AllenJB/831990a782dcfaa8f4a59b47640868bf to your computer and use it in GitHub Desktop.
Avoiding SQL Accidents in Production
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment