Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysqldump --opt --user=<youruser> --password=<yourpassword> -host <yourhost>
- <yourDB> <yourtable> | mysql -u <newserveruser> -p<password>
- ssh -C -l <remoteuser> <remoteserver>
- 'mysqldump --opt --user=<youruser> --password=<yourpassword> <yourDB> <yourtable>'
- | mysql -u <newserveruser> -p<password>
- /* set write lock on the table so it cannot be read while updating */
- LOCK TABLES mytable WRITE;
- /* update all rows which are present in mytable and newtable */
- UPDATE mytable AS M LEFT JOIN newtable AS N ON M.primarykey = N.primarykey
- SET M.column1=N.column1, M.column2=N.column2 [...]
- WHERE N.primarykey Is Not NULL;
- /* delete all rows from mytable which are no longer present in newtable */
- DELETE M FROM mytable AS M LEFT JOIN newtable AS N on M.primarykey = N.primarykey
- WHERE N.primarykey Is NULL;
- /* insert new rows from newtable */
- INSERT INTO mytable (primarykey, column1, column2, [...])
- SELECT (N.primarykey, N.column1, N.column2, [...]) FROM mytable AS M
- RIGHT JOIN newtable AS N ON M.primarykey=N.primarykey WHERE M.primarykey Is NULL
- /* release lock */
- UNLOCK TABLES;
- DELIMITER $$
- CREATE TRIGGER sync_table1_insert
- AFTER INSERT ON `table1` FOR EACH ROW
- BEGIN
- INSERT INTO table2 (id, value) VALUES (NEW.id, NEW.value);
- END;
- $$
- DELIMITER ;
- DELIMITER $$
- CREATE TRIGGER sync_table1_update
- AFTER UPDATE ON `table1` FOR EACH ROW
- BEGIN
- UPDATE table2 SET value = NEW.value WHERE id = NEW.id;
- END;
- $$
- DELIMITER ;
- DELIMITER $$
- CREATE TRIGGER sync_table1_delete
- AFTER DELETE ON `table1` FOR EACH ROW
- BEGIN
- DELETE FROM table2 WHERE id = OLD.id;
- END;
- $$
- DELIMITER ;
- #!/bin/bash
- #1
- current_date=$(date +"%m%d%y")
- echo "File name and path: /var/www/beta-"$current_date".sql"
- #2 live backup
- mysqldump -u root -proot beta > "/var/www/intelli_live-"$current_date".sql"
- #3 Beta backup:
- mysqldump -u root -proot beta_database2 --ignore-table=beta.webform_submitted_data --ignore-table=beta.webform_submissions > "/var/www/beta-"$current_date".sql"
- #4 and then have beta sql to import in live
- mysql -u root -proot beta_database < "/var/www/beta-"$current_date".sql"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement