This can be done with the following:
shell> mysqldump --all-databases > dump.sql
The --all-databases option takes a backup of all databases and all tables. The > operator redirects the output to the dump.sql file. Prior to MySQL 8, stored procedures and events were stored in the mysql.proc and mysql.event tables. From MySQL 8 onward, definitions for corresponding objects are stored in data dictionary tables, but those tables are not dumped. To include stored routines and events in a dump made using --all-databases, use the --routines and --events options.
To include the routines and events:
shell> mysqldump --all-databases --routines --events > dump.sql
You can open the dump.sql file to see how it is structured. ...