title: Mysql Warning Code 1592 Unsafe statement written to the binary log using statement format
body: <blockquote>
    <p>Note (Code 1592): Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statements writing to a table with an auto-increment column after selecting from another table are unsafe because the order in which rows are retrieved determines what (if any) rows will be written. This order cannot be predicted and may differ on master and the slave.</p>
  </blockquote>
  
  <p>I don't understand the above error message. Below are the statements/tables involved.</p>
  
  <pre class="lang-bsh prettyprint-override"><code>mysql&gt; show create table phppos_app_config;
  +-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  | Table             | Create Table                                                                                                                                                                                                                  |
  +-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  | phppos_app_config | CREATE TABLE `phppos_app_config` (
    `key` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
    `value` text COLLATE utf8_unicode_ci NOT NULL,
    PRIMARY KEY (`key`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci |
  +-------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1 row in set (0.00 sec)
  
  mysql&gt; \W
  Show warnings enabled.
  mysql&gt; CREATE TABLE IF NOT EXISTS `phppos_locations` (
      -&gt;   `location_id` int(11) NOT NULL AUTO_INCREMENT,
      -&gt;   `name` text COLLATE utf8_unicode_ci,
      -&gt;   `address` text COLLATE utf8_unicode_ci,
      -&gt;   `phone` text COLLATE utf8_unicode_ci,
      -&gt;   `fax` text COLLATE utf8_unicode_ci,
      -&gt;   `email` text COLLATE utf8_unicode_ci,
      -&gt;   `receive_stock_alert` text COLLATE utf8_unicode_ci,
      -&gt;   `stock_alert_email` text COLLATE utf8_unicode_ci,
      -&gt;   `return_policy` text COLLATE utf8_unicode_ci,
      -&gt;   `timezone` text COLLATE utf8_unicode_ci,
      -&gt;   `mailchimp_api_key` text COLLATE utf8_unicode_ci,
      -&gt;   `enable_credit_card_processing` text COLLATE utf8_unicode_ci,
      -&gt;   `merchant_id` text COLLATE utf8_unicode_ci,
      -&gt;   `merchant_password` text COLLATE utf8_unicode_ci,
      -&gt;   `default_tax_1_rate` text COLLATE utf8_unicode_ci,
      -&gt;   `default_tax_1_name` text COLLATE utf8_unicode_ci,
      -&gt;   `default_tax_2_rate` text COLLATE utf8_unicode_ci,
      -&gt;   `default_tax_2_name` text COLLATE utf8_unicode_ci,
      -&gt;   `default_tax_2_cumulative` text COLLATE utf8_unicode_ci,
      -&gt;   `deleted` int(1) DEFAULT '0',
      -&gt;   PRIMARY KEY (`location_id`),
      -&gt;   KEY `deleted` (`deleted`)
      -&gt; ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
  Query OK, 0 rows affected (0.02 sec)
  
  mysql&gt; -- -------------------------------------------------
  mysql&gt; -- Migrate app config to location ---
  mysql&gt; -- -------------------------------------------------
  mysql&gt; 
  mysql&gt; INSERT INTO `phppos_locations` (`location_id`, `name`, `address`, `phone`, `fax`, `email`,
      -&gt; `receive_stock_alert`, `stock_alert_email`, `return_policy`, `timezone`, `mailchimp_api_key`,
      -&gt;  `enable_credit_card_processing`, `merchant_id`, `merchant_password`, `default_tax_1_rate`,
      -&gt; `default_tax_1_name`,`default_tax_2_rate`, `default_tax_2_name`, `default_tax_2_cumulative`) VALUES(
      -&gt; 1,
      -&gt; 'Default',
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'address'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'phone'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'fax'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'email'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'receive_stock_alert'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'stock_alert_email'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'return_policy'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'timezone'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'mailchimp_api_key'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'enable_credit_card_processing'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'merchant_id'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'merchant_password'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'default_tax_1_rate'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'default_tax_1_name'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'default_tax_2_rate'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'default_tax_2_name'),
      -&gt; (SELECT `value` FROM phppos_app_config WHERE `key` = 'default_tax_2_cumulative')
      -&gt; );
  Query OK, 1 row affected, 1 warning (0.00 sec)
  
  Note (Code 1592): Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statements writing to a table with an auto-increment column after selecting from another table are unsafe because the order in which rows are retrieved determines what (if any) rows will be written. This order cannot be predicted and may differ on master and the slave.
  </code></pre>