Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql schema changes with master & slave

Tags:

mysql

If I have a MySQL master-slave set-up and I change the schema on the master (e.g. ALTER TABLE/CREATE TABLE, etc), will those changes get replicated over to the slave?

like image 469
BartD Avatar asked Oct 25 '10 13:10

BartD


People also ask

How do you handle database schema changes?

Updating a database schema is pretty easy if you can take your application offline. You shutdown the application, create a backup of the current database schema, perform all required update operations using tools like Flyway or Liquibase, restart the application and hope that everything works fine.

Does database schema changes very frequently?

Database schema changes are not popular among DBAs, not when you are operating production databases and cannot afford to switch off the service during a maintenance window. These are unfortunately frequent and necessary, especially when introducing new features to existing applications.

How do I update a MySQL schema?

To change the name of the default schema, double-click the schema tab. This opens a schema editor window docked at the bottom of the application. To undock or redock this window, double-click anywhere in the editor title bar. To rename the schema, use the field labeled Name.


1 Answers

The answer is actually that it depends on the type of replication you are using and how your replication setup is configured.

Statement-based replication? Applying ALTER TABLE on the master? Not using any of the non-replication-safe SQL commands [1] (e.g. non-deterministic functions such as RAND() )?

CREATE and ALTER should replicate just fine.

In some situations it may be useful to stop slave; [run script on master]; [run script on slave]; start slave; An example is here[2].

[1] http://dev.mysql.com/doc/refman/5.1/en/replication-sbr-rbr.html

[2] http://dev.mysql.com/doc/refman/5.1/en/replication-solutions-diffengines.html

like image 194
phpguru Avatar answered Oct 13 '22 00:10

phpguru