Mysql ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA

來源:互聯網
上載者:User

標籤:

ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)錯誤的原因:Mysql配置了複製,複製功能也就意味著Master資料的變化,會同步到Slave。對於函數,Mysql要求函數不能修改資料。解決辦法:1、建立函數的時候,明確說明我不會修改資料。建立函數的時候有5個選項:a、DETERMINISTIC 確定性b、NO SQL 沒有包含SQl語句,當然也不會修改資料c、READS SQL DATA 只是讀取資料,當然也不會修改資料d、MODIFIES SQL DATA 要修改資料e、CONTAINS SQL 包含了SQL語句怎麼理解DETERMINISTIC確定性?可以認為輸入相同,方法執行過程,輸出也是相同的。也就是方法的可重新進入性。不可重新進入的方法:方法內使用了靜態資料,使用了malloc和free,使用了標準I/O函數。建立函數必須明確指出a、b、c三個選項中的一個,才能執行成功。如下:mysql> show variables like ‘log_bin%‘;+---------------------------------+-------+| Variable_name                   | Value |+---------------------------------+-------+| log_bin                         | ON    || log_bin_trust_function_creators | OFF   || log_bin_trust_routine_creators  | OFF   |+---------------------------------+-------+3 rows in setmysql> create function fun1 (num int(9)) returns int(9)beginreturn 1;end;1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)mysql> create function fun1 (num int(9)) returns int(9) reads sql databeginreturn 1;end;Query OK, 0 rows affectedmysql> drop function fun1;Query OK, 0 rows affectedmysql> create function fun1 (num int(9)) returns int(9) deterministicbeginreturn 1;end;Query OK, 0 rows affected2、告訴Mysql,信任我,方法不會修改資料,Mysql不再檢查,即使修改了資料。這個時候要靠你信守承諾,否則後果自負。mysql> drop function fun1;Query OK, 0 rows affectedmysql> set global log_bin_trust_function_creators=on;Query OK, 0 rows affectedmysql> show variables like ‘log_bin%‘;+---------------------------------+-------+| Variable_name                   | Value |+---------------------------------+-------+| log_bin                         | ON    || log_bin_trust_function_creators | ON    || log_bin_trust_routine_creators  | ON    |+---------------------------------+-------+3 rows in setmysql> create function fun1 (num int(9)) returns int(9) modifies sql databeginreturn 1;end;Query OK, 0 rows affected

Mysql ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.