I'm using mysql 5.5, trying to write a script to create users, views, and grant select privileges on those views. Here's what I have so far.
set @type_id := 1;
set @username := 'somecompany';
set @password := 'company1234';
set @prefix := 'somecompany';
CREATE OR REPLACE VIEW CONCAT(@prefix, '_report') AS
SELECT * FROM my_table
WHERE type_id = @type_id;
Which won't work because it isn't looking for a string for the view name. I got around this for creating users with the statement:
INSERT INTO mysql.user (Host, User, Password) VALUES ('%', @username, PASSWORD(@password));
Is there a similar trick I can use to create views and grant select on those views to the user I created?