aws mysql sequence 사용방법
아래처럼 시퀀스를 사용하려고 하면 다음과 같은 에러가 나온다
select nextval('member_sq') as member_sq from dual
FUNCTION ebdb.nextval does not exist.
이 에러는 mysql 에는 nextval 함수가 없다 그래서 함수를 직접 만들어 줘야한다
제일 먼저 create_sequence 프로듀서를 만든다
delimiter $$
create procedure `create_sequence` (IN the_name text)
modifies sql data
deterministic
begin
delete from SEQUENCES where name = the_name;
insert into SEQUENCES values(the_name, 0);
end;
그 다음에 nextval 함수를 만든다
delimiter $$
create function `nextval` (the_name VARCHAR(32))
RETURNS BIGINT unsigned
MODIFIES SQL DATA
Deterministic
begin
declare ret BIGINT unsigned;
update SEQUENCES set currval = currval +1 where name = the_name;
select currval into ret from SEQUENCES where name = the_name limit 1;
return ret;
end;
다음과 같은 에러가 나온다. 권한이 없는 것이다
You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
mysql 을 직접 들어갈 수 있으면 다음과 같이 설정한다
set global log_bin_trust_function_creators=1;
아니면 aws 에서는 구성이라고 탭을 선택후 파라미터 그룹을 기본 말고 새로 생성헤서 위의 log_bin~ 을 찾은 다음 1로 세팅해준다음에
재부팅을 해주면 완료다
반응형