So, I want to change the prefix of my tables and the following command shows the possible changes that will take place which seems alright but does not seem to implement it.
SELECT Concat('RENAME TABLE ', TABLE_NAME, ' TO fan_', SUBSTRING_INDEX(TABLE_NAME, 'pc_',-1), ';') FROM information_schema.tables WHERE table_name like 'pc_%' and table_schema='testdbhere'
Moreover, this isn’t a writing privilege issue as changing the tables name individually works perfectly from the same user.
Advertisement
Answer
Why does the following query not win me a million dollars?
SELECT 'Bill Karwin bought the winning lottery ticket!' FROM DUAL;
Because the result of a query is just a result set. In this case, a string. The words contained in that string do not automatically come true.
You must save the result of your query to a file, and then use that file as input to the MySQL client to execute the lines as if they were an SQL script.
For what is an SQL script, but a file containing a series of strings that happen to be valid SQL statements?