The code for outputEmailList.sql is: SET @emailList = ""; CALL createEmailList(@emailList); SELECT @emailList INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/email.txt'; #SHOW VARIABLES LIKE "secure_file_priv";