Database design: keys, relationships and normalization
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
Create a reliable backup with mysqldump, restore it, and set up a routine so you never lose data.
Servers fail, updates break things, and people delete the wrong rows. A backup you have tested is the only real protection.
mysqldump -u root -p --single-transaction --routines --triggers mydb > mydb_backup.sql--single-transaction gives a consistent copy of InnoDB tables without locking them.mysqldump ... mydb | gzip > mydb_backup.sql.gzOn WampServer the program is in the MySQL bin folder; run it from a command prompt opened in that folder.
mysql -u root -p mydb < mydb_backup.sqlCreate the empty database first if it doesn’t exist:
CREATE DATABASE mydb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;Once in a while, restore it into a different database (mydb_test) and open the site against it. A backup that has never been restored is only a hope.
For small sites: Export → Custom → SQL, tick *Add DROP TABLE* if you want to replace existing tables, and save the file.
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
A folder layout and a few habits that keep a growing PHP site tidy, secure and easy to maintain.