Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-11-29 · container image mysql:8.4
When binary logging is enabled (the default in MySQL 8.x), MySQL refuses to create a stored function unless its declaration says what kind of function it is: DETERMINISTIC, NO SQL or READS SQL DATA. Without one of these, CREATE FUNCTION fails with ERROR 1418 and the function is not created.
In the runs below log_bin was ON and log_bin_trust_function_creators was OFF. Adding the right characteristic to the declaration was enough; no server setting was changed. The tests ran as root.
01Calculation function declared with no characteristic
CREATE FUNCTION add_tax(p INT) RETURNS INT RETURN ROUND(p * 1.1) failed with ERROR 1418. SHOW VARIABLES showed log_bin ON and log_bin_trust_function_creators OFF.
The function always returns the same result for the same input, so adding DETERMINISTIC after RETURNS INT is accurate. With it the function was created and SELECT add_tax(1000) returned 1100.
Setup
CREATE DATABASE shop;Query OK, 1 row affected (0.01 sec)USE shop;
CREATE FUNCTION add_tax(p INT) RETURNS INT
RETURN ROUND(p * 1.1);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)SHOW VARIABLES WHERE Variable_name IN ('log_bin', 'log_bin_trust_function_creators');+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin | ON |
| log_bin_trust_function_creators | OFF |
+---------------------------------+-------+
2 rows in set (0.01 sec)USE shop;
CREATE FUNCTION add_tax(p INT) RETURNS INT DETERMINISTIC
RETURN ROUND(p * 1.1);
SELECT add_tax(1000) AS price;Query OK, 0 rows affected (0.00 sec)
+-------+
| price |
+-------+
| 1100 |
+-------+
1 row in set (0.00 sec)02Function that runs a SELECT, declared with no characteristic
customer_name(p_id) returns (SELECT name FROM customers WHERE id = p_id). Created without a characteristic it failed with ERROR 1418, and information_schema.ROUTINES showed no routine in the database.
The function reads a table but changes nothing, so READS SQL DATA describes it. With RETURNS VARCHAR(20) READS SQL DATA it was created and SELECT customer_name(1) returned Kim.
Setup
CREATE DATABASE shop;
CREATE TABLE shop.customers (id INT PRIMARY KEY, name VARCHAR(20));
INSERT INTO shop.customers VALUES (1, 'Kim');Query OK, 1 row affected (0.01 sec)
Query OK, 0 rows affected (0.02 sec)
Query OK, 1 row affected (0.00 sec)USE shop;
CREATE FUNCTION customer_name(p_id INT) RETURNS VARCHAR(20)
RETURN (SELECT name FROM customers WHERE id = p_id);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)SELECT ROUTINE_NAME FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = 'shop';Empty set (0.01 sec)USE shop;
CREATE FUNCTION customer_name(p_id INT) RETURNS VARCHAR(20) READS SQL DATA
RETURN (SELECT name FROM customers WHERE id = p_id);
SELECT customer_name(1) AS name;Query OK, 0 rows affected (0.01 sec)
+------+
| name |
+------+
| Kim |
+------+
1 row in set (0.00 sec)FAQ
How do I fix MySQL error 1418 without changing server settings?
Add DETERMINISTIC, NO SQL or READS SQL DATA to the function declaration, after RETURNS. Both runs above were fixed that way with log_bin_trust_function_creators left OFF.
Should I use DETERMINISTIC or READS SQL DATA?
Use DETERMINISTIC when the result depends only on the arguments, like add_tax above. Use READS SQL DATA when the function runs a SELECT, like customer_name above.
What about SET GLOBAL log_bin_trust_function_creators = 1?
The error message suggests it, but it is a server-wide setting that MySQL itself calls less safe. It was not used here; declaring the characteristic fixed both cases.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13