MySQL & MariaDB error 1418: This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA
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_b (8.0.46) With binary logging on, MySQL refuses to create a stored function that doesn't declare whether it is deterministic or modifies data, because it can't tell whether replicas would compute the same result.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_BINLOG_UNSAFE_ROUTINE | ER_BINLOG_UNSAFE_ROUTINE |
| SQLSTATE | HY000 | HY000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
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).
When statements are written to the binary log for replication or point-in-time recovery, a function that isn’t deterministic could give a different result on a replica. So CREATE FUNCTION must declare its characteristics, or the server must be told to trust function creators.
Why it happens
- MySQL 8.0 turned binary logging on by default. Function definitions that worked on 5.7 (where
log_binwas off unless configured) fail on 8.0+. Our tests show 1418 on MySQL 8.0, 8.4 and 9.x but not on 5.6/5.7 or the default MariaDB configuration, where binary logging is off. - Restoring a dump with functions into a server with binary logging on.
How to fix it
- Declare what the function does:
DETERMINISTIC(same input, same output) and/orNO SQL/READS SQL DATA. Only declareDETERMINISTICif it is true. - Or, as an administrator,
SET GLOBAL log_bin_trust_function_creators = 1;(and inmy.cnf). That is needed when users without SUPER create functions; understand the replication trade-off first.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database:CREATE DATABASE demo; USE demo;Run:
CREATE FUNCTION add_tax(p DECIMAL(10,2)) RETURNS DECIMAL(10,2) RETURN p * 1.23;
You get: 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)(9.7.4)
Verified fixes
Declare what the function does: DETERMINISTIC / NO SQL / READS SQL DATA
CREATE FUNCTION add_tax(p DECIMAL(10,2)) RETURNS DECIMAL(10,2) DETERMINISTIC NO SQL RETURN p * 1.23; SELECT add_tax(100);
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| Create a function without a characteristic while binary logging is on repro | ≠ | ≠ | ✓ 1418 | ✓ 1418 | ✓ 1418 | ≠ | ≠ | ≠ | ≠ |
| Is binary logging on? (default ON from MySQL 8.0; OFF in the MariaDB images) version check | ≠ | ≠ | ✓ | ✓ | ✓ | ≠ | ≠ | ≠ | ≠ |
| Declare what the function does: DETERMINISTIC / NO SQL / READS SQL DATA fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
What the warnings and failures say (2)
- Create a function without a characteristic while binary logging is on (MySQL 5.6, MySQL 5.7, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): expected error 1418 did not occur
- Is binary logging on? (default ON from MySQL 8.0; OFF in the MariaDB images) (MySQL 5.6, MySQL 5.7, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): rows differ
Related errors
Where this error shows up in our guides
- Basic hash jumbler function · Same function without NO SQL / DETERMINISTIC (does binlog default trigger 1418?) MySQL 8.0 8.4 9