-
Notifications
You must be signed in to change notification settings - Fork 0
Backups
Your players' accounts live in MySQL. If the disk dies or a bad query wipes a table and you have no backup, it's gone. This page covers keeping the data safe — it's about MySQL administration, not omp-MySQL specifically, but every server owner needs it.
mysqldump writes your whole database to a single .sql text file you can restore
later.
# back up one database to a file
mysqldump -u root -p --single-transaction --routines mydb > mydb-backup.sql
# restore it (into an existing, empty database)
mysql -u root -p mydb < mydb-backup.sql-
--single-transactiontakes a consistent snapshot without locking players out (works for InnoDB, the default engine). -
--routinesincludes stored procedures/functions if you have any.
Compress big dumps:
mysqldump -u root -p --single-transaction mydb | gzip > mydb-$(date +%F).sql.gzA backup you have to remember to run is a backup you won't have. Schedule it.
Linux (cron) — daily at 4am, keep 14 days:
# crontab -e
0 4 * * * mysqldump -u backup -pYOURPASS --single-transaction mydb | gzip > /backups/mydb-$(date +\%F).sql.gz && find /backups -name 'mydb-*.sql.gz' -mtime +14 -deleteDocker MySQL:
docker exec mysql mysqldump -uroot -prootpw --single-transaction mydb | gzip > mydb-$(date +%F).sql.gzStore backups off the server too (another disk, another machine, cloud). A backup on the same disk that dies is no backup.
Untested backups fail when you need them. Every so often, restore your latest dump into a throwaway database and check it's intact:
mysql -u root -p -e "CREATE DATABASE restore_test"
gunzip < mydb-2025-01-01.sql.gz | mysql -u root -p restore_test
mysql -u root -p restore_test -e "SELECT COUNT(*) FROM accounts"About to run an ALTER TABLE, a mass UPDATE/DELETE, or a schema migration? Take a
fresh dump first. And always write destructive statements with a WHERE:
-- terrifying: UPDATE accounts SET money = 0; (every player!)
-- correct: UPDATE accounts SET money = 0 WHERE id = 5;- Keep MySQL updated within your major version for security fixes (8.4.x → 8.4.y).
- Monitor disk space — a full disk corrupts databases and stops writes.
-
Check the error log (
mysqld.err/journalctl -u mysql) occasionally. - For omp-MySQL specifically, watch
mysql_pending_countand the[omp-MySQL]debug log if queries seem slow (see Performance).
To move your database to another machine: mysqldump on the old, copy the file,
mysql < file on the new, recreate the DB user (with REQUIRE SSL), point
omp-MySQL's host at the new server. See Configuration.
Next: Security · Performance
Understand
Use
- Installing MySQL
- Docker Compose
- Getting started
- Configuration
- SQL crash course
- Designing your tables
- Storing game data
- Dates & times
- First queries
- Async patterns
- Reading results
- Prepared statements
- Passwords & hashing
- Transactions
- Models (active-record)
- Tutorial: login system
- mysql-admin demo
Deeper
Reference