As documented under SELECT Syntax:
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants, with these exceptions:
Within prepared statements, LIMIT parameters can be specified using ? placeholder markers.
Within stored programs, LIMIT parameters can be specified using integer-valued routine parameters or local variables.
Therefore LIMIT parameters can never be user-defined variables. Your options, as indicated above, are to use either:
prepared statements
PREPARE stmt FROM '
select * from my_table where flagged=1 order by 21_day_probability limit ?
';
EXECUTE stmt USING @v1;
DEALLOCATE PREPARE stmt;
a parameter/local variable within a stored program:
CREATE PROCEDURE foo(_l INT)
select * from my_table where flagged=1 order by 21_day_probability limit _l
;
CALL foo(@v1);