I have two database in one mysql server database_master and database_backup.
I would like database_backup to copy all new data that inserted into or updated at database_master.
But is there is some data deleted on database_master, the data on database_backup will be still remain.
How can we do that in MySQL?
To be clear, I take it that you want replication, but not to replicate deletes of records. This cannot be done with the native replication (neither row nor statement based). The main reason is if on the main db you deleted a row then inserted a row the new row might get the old row’s primary key. On the replica db this would cause a key conflict.
However, to do some kind of hack audit logging, you could create on the slave mysql server one logging table for each actual DB table. For example, if you had a table
fooyou would create a correspondingfoo_loggingtable. The logging tables would have every column in the original, plus a seperate auto-incrementing primary key. You’d then put a trigger on the original table to insert a copy of any new or updated record into it’s corresponding logging table.