Category Archives: bash – one liners

How to execute MySQL query / statement from the shell (command line)

mysql -hhostname -uusername -ppassword db_name -e 'query to execute;'
  • hostname – the host on which MySQL is installed
  • username – the MySQL user┬áthat has the necessary privileges over the database
  • passsword – the MySQL user password
  • db_name – the name of the MySQL database that you want to query
  • -e – MySQL option which will execute the statement and quit
  • query to execute; – the MySQL query you want to execute enclosed in single quotes

Generate random usernames / email addresses list with apg

apg is a handy utility for creating random passwords / strings. To install it run:

apt-get install apg

The below for loop will create 300 random usernames / email addresses in the format You can always replace “domain” with “$i” , then you’ll have addresses in the format

-M – specifies that mode will be used
L – use small letters only mode
-n – number of passwords/random strings, in this case 300

for i in $(apg -M L -n 300); do echo $ >> fileToSaveResult ; done