解决新版mysql创建函数的问题you *might* want to use the less safe log_bin_trust_function_creators variab
今天在部署一个测试环境的时候发现mysql结构同步时函数操作失败,看了一下问题:
you *might* want to use the less safe log_bin_trust_function_creators variab
这时候修改一下配置的 log_bin_trust_function_creators 即可,我直接在终端执行:
SET GLOBAL log_bin_trust_function_creators = 1;
后发现创建函数正常了。
雪花Id脚本
CREATE FUNCTION `SnowId`() RETURNS bigint(20)BEGIN
DECLARE b_current_time BIGINT;
DECLARE b_time_tick BIGINT;
DECLARE i_work_id INT;
DECLARE i_work_id_big_length INT;
DECLARE i_seq_big_length INT;
DECLARE f_random FLOAT;
DECLARE b_res BIGINT;
SET i_work_id = 1;
SET i_work_id_big_length = 4;
SET i_seq_big_length = 8;
SET b_current_time = (REPLACE(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)),'.','')) + 0;
SET b_time_tick = b_current_time - 1582136402000;
SET f_random = RAND();
SET b_res = b_time_tick POWER(2, i_work_id_big_length + i_seq_big_length) + i_work_id POWER(2, i_seq_big_length) + (5 + round((POWER(2, i_seq_big_length)-1) * f_random, 0));
RETURN b_res;
END
<br/>