sqlmysqlunixcommand-line

How do you run a single query through mysql from the command line?


I'm looking to be able to run a single query on a remote server in a scripted task.

For example, intuitively, I would imagine it would go something like:

mysql -uroot -p -hslavedb.mydomain.com mydb_production "select * from users;"

Solution

  • mysql -u <user> -p -e 'select * from schema.table'
    

    (Note the use of single quotes rather than double quotes, to avoid the shell expanding the * into filenames)