michahell
9/28/2015 - 11:32 AM

MySQL SHOW databases alias

MySQL SHOW databases alias

If you ever need to execute the following SQL statement in MySQL:

SHOW databases; or especially SHOW databases LIKE 'somePrefix_%'; and you want to alias or name the returned dataset, you can't do that with the SHOW statements as they are very limited. You can however do this if you make use of the INFORMATION_SCHEMA default MySQL table:

SELECT SCHEMA_NAME AS `Database` FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME LIKE 'somePrefix_%';

You're welcome!