How to retrieve the query I used to create a view?

View definitions are stored in the information schema:

SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS
   WHERE TABLE_NAME = 'yourviewname'

You can use the documented feature SHOW CREATE VIEW view_name which is documented on the official dev.MySQL.com website:

Reference:
13.7.5.14 SHOW CREATE VIEW Syntax (Version 5.5)
14.7.5.13 SHOW CREATE VIEW Syntax (Version 5.7)

mysql> SHOW CREATE VIEW v\G
*************************** 1. row ***************************
                View: v
         Create View: CREATE ALGORITHM=UNDEFINED
                      DEFINER=`bob`@`localhost`
                      SQL SECURITY DEFINER VIEW
                      `v` AS select 1 AS `a`,2 AS `b`
character_set_client: latin1
collation_connection: latin1_swedish_ci