DELIMITER //

-- Create procedure --
DROP PROCEDURE IF EXISTS qwoss.createUser
//

CREATE PROCEDURE qwoss.createUser()
    BEGIN
	DECLARE a CHAR(16);
	DECLARE cur CURSOR FOR SELECT `user` FROM mysql.db WHERE `user` = 'qwoss' and `db` = 'qwoss';
	DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' 
		BEGIN 
		  CREATE USER qwoss IDENTIFIED BY 'qwoss';
		  GRANT ALL ON qwoss.* TO 'qwoss'@'%';	
		END;
	
	OPEN cur;
		
	FETCH cur INTO a;

	CLOSE cur;

    END
//

-- end createUser procedure --
call qwoss.createUser()
//