Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Mysql and using back ticks in the bash shell</strong></p> <p>A query like the following will fail since the back tick character has special meaning in the shell:</p> <pre><code>mysql -u root -pPass mydb -e "select `work-time` from work" </code></pre> <p>The back tick character must either be escaped or used inside a single quoted string when executing sql from the shell. An example of a single quoted string is the following:</p> <pre><code>mysql -u root -pPass mydb -e 'select `work-time` from work' </code></pre> <p>To accomplish the same query using double quotes we would need to escape the back tick character like so:</p> <pre><code>mysql -u root -pPass mydb -e "select \`work-time\` from work" </code></pre> <p>I suggest reading up on the <a href="http://www.howtogeek.com/howto/29980/whats-the-difference-between-single-and-double-quotes-in-the-bash-shell/">difference between double quotes and single quotes</a> in the bash shell.</p> <hr> <p><strong>Example Problem 1:</strong></p> <pre><code>"select `work-time` from work where `work-time`&gt; '2013-0-3-07 00:00:00'" </code></pre> <p>The above query will not work. However, you can accomplish this with single quotes but you will need to escape any single quotes that are inside the query like so:</p> <pre><code>'select `work-time` from work where `work-time`&gt; \'2013-0-3-07 00:00:00\'' </code></pre> <hr> <p><strong>Example Problem 2:</strong></p> <pre><code>"select \`work-time\` from work where \`work-time\`&gt; \'2013-0-3-07 00:00:00\'" </code></pre> <p>The above query is almost good as you do need to escape the back tick since it has special meaning. However, you do not need to escape the single quotes. With double quotes the query can look like the following:</p> <pre><code>"select \`work-time\` from work where \`work-time\`&gt; '2013-0-3-07 00:00:00'" </code></pre> <hr> <p><strong>Back ticks inside a SQL file</strong></p> <p>If you then decided you wanted to put this query in a file and send it to mysql you would no longer need to escape the back tick character since the back tick character has no special meaning inside a sql file. In the file you would just put the standard SQL:</p> <pre><code>select `work-time` from work where `work-time` &gt; '2013-0-3-07 00:00:00' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload