Dumping a sample from a MySQL instance or a database

Say you want to dump a database, or even all databases, but with just a sample of all the data, say, 10 000 records per table of each of the databases.
Here’s a way to do that:

Reference: http://stackoverflow.com/questions/135835/limiting-the-number-of-records-from-mysqldump