How to import sql file in stored procedure in MySQL? What I want to do is as follows.

In a stored procedure:


Access the DB to retrieve some record of a file name X
Check whether a file named X.sql exists
source X.sql; (or something similar)


Is that doable? Or do I have to go to UDF?

Thanks.
Not everything can be done in SQL.  In particular, it is not possible (without a UDF) to reach outside of MySQL to do file operations (other than LOAD FILE).  This is a security limitation.

The "right" way to deal with a requirement is to code it in your application language (PHP / Java / Python / ...).  Some steps would be SQL; some would be file operations.