Although the mysql environment is convenient for entering small queries, it can be very tedious to enter long queries. If you find that a query is getting overly long or needs serious editing, type \e at the end of the query and press Enter. This feature is not available on Windows systems.
The editor referred to by the $EDITOR environment variable opens, with the query to be edited already in place. Edit the query as you would any other text, save the file (which will have an odd-looking name), and exit the editor.
The query is loaded into mysql, but is not executed. To execute the query, type ; (or \G to display the query results in a list instead of in a table), and press Enter.
See your shell documents for information on how to set the $EDITOR environment variable.
The default editor might be vi or vim. Although these are both fine editors, they can be very challenging to use for those unfamiliar with them. If you want to bravely forge ahead, type :help<enter> to get help on using the editor. If you want to sensibly retreat, type :q!<enter>.