Mysql and using reverse ticks in a bash shell
A query like the one below will fail, because the backslash character has special meaning in the shell:
mysql -u root -pPass mydb -e "select `work-time` from work"
The back tick symbol must either be escaped or used inside the same quote when executing sql from the shell. Example of one line with quotes:
mysql -u root -pPass mydb -e 'select `work-time` from work'
To execute the same query using double quotes, we would need to avoid the reverse tick:
mysql -u root -pPass mydb -e "select \`work-time\` from work"
I suggest reading the difference between double quotes and single quotes in the bash shell.
Example Problem 1:
"select `work-time` from work where `work-time`> '2013-0-3-07 00:00:00'"
The above query will not work. However, you can do this with single quotes, but you will need to avoid any single quotes that are inside the query, for example:
'select `work-time` from work where `work-time`> \'2013-0-3-07 00:00:00\''
Example Problem 2:
"select \`work-time\` from work where \`work-time\`> \'2013-0-3-07 00:00:00\'"
The above query is almost good, since you need to avoid the back tick, as it has special meaning. However, you do not need to avoid single quotes. With double quotes, the query might look like this:
"select \`work-time\` from work where \`work-time\`> '2013-0-3-07 00:00:00'"
Reverse ticks inside an SQL file
If you decide that you want to put this query in a file and send it to mysql, you will no longer need to avoid the back tick symbol, since the back tick symbol does not have much meaning inside the sql file. In the file, you simply put standard SQL:
select `work-time` from work where `work-time` > '2013-0-3-07 00:00:00'