Announcement

Announcement Module
Collapse
No announcement yet.

Unsafe statement written to the binary log

Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unsafe statement written to the binary log

    Hello Everyone,

    I am not sure when and how did this happen, But i just happen do view my log file files and i was surprised to see it throwing up this errors continuously like this :-

    tail -f /var/lib/mysql/Newdbsrv.err

    130708 16:54:21 [Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. CREATE... IGNORE SELECT is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are ignored. This order cannot be predicted and may differ on master and the slave. Statement: create temporary table IF NOT EXISTS vt_tmp_u1098(id int(11) primary key) ignore (SELECT 1098 as id) UNION (SELECT vtiger_user2role.userid AS userid FROM vtiger_user2role INNER JOIN vtiger_users ON vtiger_users.id=vtiger_user2role.userid INNER JOIN vtiger_role ON vtiger_role.roleid=vtiger_user2role.roleid WHERE vtiger_role.parentrole like 'H1::H2::H31::H32::%') UNION (SELECT groupid FROM vtiger_groups where groupid in (777,778))
    As i am not sure what this is and what it means, I am seeking your kind and humble support.

    I would also like to point out that my server was rebooted 48 hrs ago, could this be the reason for the same ?

    I also have a replication server setup and it seems to be functioning normally.

    would appreciate your kind revert into this.

    Thank you every one !!

  • #2
    Hi Guys,

    I am just bumping this thread, just to gain some attention.

    I would appreciate some suggestions !!

    any one ?

    Thank you

    Comment


    • #3
      Hello niljoshi and przemek,

      Since there was a glitch on the forums which had temporarily removed several posts over the last few days .

      Would you be kind enough to please repeat your response that you had provide me earlier as it is no more online

      Thank you so very much for your time once again.

      Comment


      • #4
        The error message it gives you is pretty good actually. Basically the statement that it is warning you about could potentially end up with different results when it runs on the slave versus when it ran on the master. This is something that a tool like Percona's pt-table-checksum (see below link) can help with to detect what is called slave drift or data drift, which is when the slave has different data than the master.

        What to actually do about this (other than check your tables with the tool I mentioned) depends on the situation. The query it is warning you about may end up working perfectly fine, but you would not know for sure without checking, and even then it may work sometimes and not others.

        The best option in my opinion is to switch to row based replication to avoid this, as then MySQL is replicating the data itself and not the statement. Row based replication has some downsides, mainly that more data is transferred, so slave lag may be more of an issue in extreme cases, so you'll want to read up on that first before making any changes.

        The other option would be to re-write the query to avoid any functions / formatting that results in unsafe queries for statement best replication (see below link).

        http://www.percona.com/doc/percona-t...-checksum.html
        http://dev.mysql.com/doc/refman/5.5/...n-formats.html
        http://dev.mysql.com/doc/refman/5.5/...fe-unsafe.html

        Comment


        • #5
          Hello Scott,

          Firstly accept my appreciation for looking into my thread and paying heed to it.

          Secondly to just switch to "ROW" based replication, I can see that all i need to do is specify the command globally for all.
          like this :- mysql> SET GLOBAL binlog_format = 'ROW';

          ** NOTE :- i guess this can be done on the fly without any restart, am i correct ?


          Further, I was also going further through the doc link that you have provided with regards to ROW based replication and i could also see it ALSO mentions about "Mixed replication (statement and row based replication)". Could you suggest if this is also a viable option ? :-

          http://dev.mysql.com/doc/refman/5.1/...log-mixed.html

          would you clear the sky on this too ?

          Once again, Thank you for every thing



          Comment


          • #6
            Mixed format does pretty much what it sounds like, but I've never used it myself and have not seen many other people using it. So that choice is up to you, but I would make sure to research / test it first.

            The binlog_format variable is dynamic, so you may change it at any point. The cleanest way would be to set it in your my.cnf on the master and restart the server, otherwise you can stop replication on your slave, change the setting dynamically on the master, and then start replication on your slave so that it picks up the change since a change in global variables only applies to new connections.

            Comment


            • #7
              Fantastic,

              I'll have this done in the coming week the very first thing and shall provide an update on it

              Thank you so very much,

              Seriously, you have taught me many a things i would have not known !!!!

              Comment


              • #8
                Hi,

                I'm sorry about those replies being lost.
                I can now only add that the MIXED mode is a good compromise between statement and ROW, and will work for the statement you had in warning message. Basically, for any data update that is "unsafe" from replication point of view, MySQL will log all changed rows values instead of the original statement. But it will keep logging other updates the same way as in statement mode.

                Comment


                • #9
                  Thank you for your revert once again przemek,

                  Sincerely appreciate it,

                  I shall post back once i have done the changes tomorrow !!

                  Thank you,

                  Comment


                  • #10
                    Hello Scott,

                    I have gone ahead and used the mixed mode replication and it has been more than 6 hours and both the servers seem to be doing fine with NO errors being reported et all on the Master Server.

                    Thanks to you and przemek, i find this issue to be resolved.

                    Thank you so so very much

                    Comment


                    • #11
                      Nice work! Just make sure to check for slave drift occasionally using a tool like pt-table-checksum since you are still using statement based replication with the mixed format.

                      http://www.percona.com/doc/percona-t...-checksum.html

                      Comment


                      • #12
                        Scott,

                        My apologies for the delayed turnaround,

                        You mean to say "statement based replication" should NOT be used with mixed mode replication or NOT be used et all, Instead always use "row based replication", is this more safer and should this be preferred over "statement" ?

                        Can you please clarify this,

                        I think i am doing a merry-go-round here , apologies for that!!

                        Comment


                        • #13
                          In "MIXED" mode, replicated transactions are written in either of two formats: row based logging, or statement based login. MySQL decides to use statement or row based log entry if it considers a given statement is "safe" or not. So "safe" updates will be logged just like in the STATEMENT binlog format, and "not-safe" will be logged as row-based events. This way the MIXED mode is more safe then STATEMENT from data integrity point of view. It's just a compromise between pure STATEMENT or pure ROW modes.
                          Now, whether to use pure ROW format, we can argue, as there are many pros and cons of this solution, take a look here:
                          http://dev.mysql.com/doc/refman/5.5/...n-sbr-rbr.html

                          The fact is, that starting from MySQL 5.6, ROW based replication works much better then in previous versions.

                          Comment


                          • #14
                            A bit off topic I guess, but I wonder, why does pt-table-checksum requires STATEMENT based binlog? It fills up my MySQL error log with warnings about unsafe statements...

                            Comment


                            • #15
                              It's quite simple, in order to calculate checksum numbers for data in order to later compare them between master and slave, those calculations have to be done separately on master and slave. With ROW binary format, the slave is only applying row changes from master, so the checksum table would be the same. Yet we need statements replicated to slaves, not data. But that's just per pt-table-checksum session setting, all the rest traffic goes via globally set binlog format.

                              Comment

                              Working...
                              X