I wanted to grant privileges on some selected tables only. So far I could only gather the necessary queries but unable to execute those.
SELECT
CONCAT('GRANT SELECT ON drupal.', TABLE_NAME, ' to ''test'';') As queryStrings
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_SCHEMA = 'drupal' AND TABLE_NAME LIKE 'cache%';
OUTPUT:
+----------------------------------------------------------------+
| queryStrings |
+----------------------------------------------------------------+
| GRANT SELECT ON drupal.cache_page to 'test'; |
| GRANT SELECT ON drupal.cachetags to 'test'; |
| GRANT SELECT ON drupal.cache_config to 'test'; |
| GRANT SELECT ON drupal.cache_data to 'test'; |
| GRANT SELECT ON drupal.cache_entity to 'test'; |
| GRANT SELECT ON drupal.cache_discovery to 'test'; |
| GRANT SELECT ON drupal.cache_default to 'test'; |
| GRANT SELECT ON drupal.cache_render to 'test'; |
| GRANT SELECT ON drupal.cache_container to 'test'; |
| GRANT SELECT ON drupal.cache_toolbar to 'test'; |
| GRANT SELECT ON drupal.cache_bootstrap to 'test'; |
| GRANT SELECT ON drupal.cache_menu to 'test'; |
| GRANT SELECT ON drupal.cache_dynamic_page_cache to 'test'; |
+----------------------------------------------------------------+
Is there something like EXECUTE queryStrings;
?
I tried to store it in a variable like
SET @query = CONCAT('GRANT SELECT ON drupal.', TABLE_NAME, ' to ''test'';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'drupal' AND TABLE_NAME LIKE 'cache%');
But I am getting error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'drupal' AND TABLE_NAME LIKE' at line 1
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'drupal' AND TABLE_NAME LIKE' at line 1
. Sorry I am a beginner here.