DROP TABLE IF EXISTS `user_group_privileges`; CREATE TABLE `user_group_privileges` ( `user_group` varchar(81) NOT NULL DEFAULT '', `schema` varchar(81) NOT NULL DEFAULT '', `privilege_type` varchar(64) NOT NULL DEFAULT '', `isa` enum('TABLE','PROCEDURE','FUNCTION') NOT NULL DEFAULT 'TABLE', UNIQUE KEY `user_table_priv` (`user_group`,`schema`,`privilege_type`), KEY `user_group` (`user_group`), KEY `schema` (`schema`), KEY `privilege_type` (`privilege_type`), KEY `isa` (`isa`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `user_group_privileges` VALUES ('developers','suma_prod.*','ALL','TABLE'),('toc','toc.*','UPDATE','TABLE'),('toc','toc.*','DELETE','TABLE'),('toc','toc.*','INSERT','TABLE'),('toc','toc.*','SELECT','TABLE'),('test','*.*','SELECT','TABLE'),('all','*.*','USAGE','TABLE'),('newgroup','`mydb`.*','SELECT','TABLE'),('newgroup','`mydb`.*','UPDATE','TABLE'),('newgroup','`mydb`.*','INSERT','TABLE'),('newgroup','`mysql_meta`.`Blag`','EXECUTE','PROCEDURE'),('all','*.nothing','DELETE','TABLE'); SELECT GROUP_CONCAT( `privilege_type` SEPARATOR ', ' ),`schema` FROM `user_group_privileges` m WHERE m.`user_group`='newgroup' AND m.`isa`='TABLE' GROUP BY m.`schema`,m.`user_group`; SELECT GROUP_CONCAT( `privilege_type` SEPARATOR ', ' ),`schema` INTO @user_privileges_table, @user_schema FROM `user_group_privileges` m WHERE m.`user_group`='newgroup' AND m.`isa`='TABLE' GROUP BY m.`schema`,m.`user_group`; SELECT @user_privileges_table, @user_schema;