MySQL shebang

The mysql command line client cannot be used in a script's shebang line like many other languages such as bash and perl and etc allow. Patches have been submitted, but so far none of them have been accepted.

A quick work-around is to create a simple wrapper script like this:

If you make that executable and put it in your PATH, then you can do something simple like this:

Note that this also allows you pass any additional command line options and they will be passed through to mysql:

connections.sql -u mysqluser -p

1 comment:

  1. Thanks! This worked perfectly. Also, if you put the mysqlscript in the same directory you can use

    #!/usr/bin/env ./mysqlscript

    which works nice if you want to keep it within the project rather than global.