delimiter $$
create PROCEDURE defaultpassword()
BEGIN
DECLARE id varchar(64);
-- 遍历数据结束标志
DECLARE done INT DEFAULT FALSE;
-- 游标
DECLARE usertable CURSOR FOR select user_id from sys_user_info;
-- 将结束标志绑定到游标
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-- 打开游标
OPEN usertable;
-- 遍历
read_loop: LOOP
-- 取值 取多个字段
FETCH NEXT from usertable INTO id;
IF done THEN
LEAVE read_loop;
END IF;
update sys_user_info set password=md5(concat(id,'123456')) where user_id=id;
END LOOP;
-- 关闭游标
CLOSE usertable;
END;
$$