For development under multiple mysql instances, you need to pay attention to the master-slave synchronization delay. This evening the server went online for testing and encountered a problem! After a piece of data is written to the database, the record cannot be read and a null pointer is reported. It's hard to understand. Call the development team lead to locate the problem. He explained that write operations use the master database, while read operations use the slave database. After writing the database
For development under multiple mysql instances, you need to pay attention to the master-slave synchronization delay. This evening the server went online for testing and encountered a problem! After a piece of data is written to the database, the record cannot be read and a null pointer is reported. It's hard to understand. Call the development team lead to locate the problem. He explained that write operations use the master database, while read operations use the slave database. After writing the database
Pay attention to the master-slave synchronization delay for development under multiple mysql instances
This evening, the server went online for testing and encountered a problem!
After a piece of data is written to the database, the record cannot be read and a null pointer is reported. It's hard to understand. Call the development team lead to locate the problem. He explained that write operations use the master database, while read operations use the slave database. After writing a database, this record does not appear in the read database immediately. It takes some time to synchronize data to the slave database. So I encountered a null pointer exception.
Back to read a lot of online Introduction to the master-slave synchronization mechanism. This is generally the case. After the master database executes the SQL write command, it writes the log to binlog. A thread in the slave database pulls the log file from the master database to obtain new data write operation logs. Write the pulled logs to the local relay-log. The SQL thread of the slave database is stored in the relay-log of the local machine.
Retrieve the log and execute it. So far, synchronization is complete. It can be seen that the synchronization between the master and slave nodes takes some time.
Good soldiers won't jump into the same trap. If you encounter similar problems in the future, the correct method is to query the data immediately after writing the data, you need to use the primary database (write database) for query instead of the slave database (read database ). I want to share my experience with you.