Puoi creare un'istruzione SQL dinamica ed eseguirla:
SET @tablename = 'MyTable';
SELECT @query := CONCAT('RENAME TABLE `', @tablename, '` TO `',
CURDATE(), @tablename, '`');
PREPARE STMT FROM @query;
EXECUTE STMT;
Il curdate() La funzione restituisce la data corrente come stringa nel formato yyyy-MM-dd .
PS Non puoi eseguire istruzioni su più righe come questa dal browser delle query, ma puoi inserirle in un file (ad esempio chiamato commandfile.sql ) ed eseguili come:
mysql -u <user> -p<password> <dbname> < commandfile.sql