title: CREATE TABLE - Works in MySQL but not in Bash
body: <p>I'm writing a <code>bash</code> script that connects to <code>mysql</code> and creates a database as follows:</p>
  
  <p><code>mysql -u root -e "CREATE DATABASE test;"</code></p>
  
  <p>I see the database gets created using the following command:</p>
  
  <p><code>mysql -u root -e "SHOW databases;"</code></p>
  
  <p>Which outputs:</p>
  
  <pre><code>+--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | mysql              |
  | performance_schema |
  | sys                |
  | test               |
  +--------------------+
  </code></pre>
  
  <p>Now I wish to <code>USE</code> this newly created database and <code>CREATE TABLE</code>, hence I run this code:</p>
  
  <pre><code>mysql -u root -e "USE test;"
  mysql -u root -e "SELECT DATABASE();"
  mysql -u root -e "CREATE TABLE information (id bigint NOT NULL AUTO_INCREMENT, name varchar(128), value_one int(255), value_two int(255), value_three int(255), value_four int(255), value_five bigint, value_six bigint);"
  </code></pre>
  
  <p>In order for me to see which database is selected, the <code>SELECT DATABASE();</code> statement returns:</p>
  
  <pre><code>+------------+
  | DATABASE() |
  +------------+
  | NULL       |
  +------------+
  </code></pre>
  
  <p>The <code>CREATE TABLE</code> statement gives me this error:</p>
  
  <pre><code>ERROR 1046 (3D000) at line 1: No database selected
  </code></pre>
  
  <p>Alternatively, I tried joining these together:</p>
  
  <p><code>mysql -u root -e "USE test; CREATE TABLE information (...);"</code></p>
  
  <p>With no exit at all. I still get the same error.</p>
  
  <p>Given that <code>mysql</code> supports a connection to the database directly in the command:</p>
  
  <p><code>mysql test -u root -e "CREATE TABLE information (...);"</code></p>
  
  <p>Or as per this <a href="https://stackoverflow.com/questions/20033648/how-to-run-mysql-command-on-bash">response</a>:</p>
  
  <p><code>mysql --database=test -u root -e "CREATE TABLE information (...);"</code></p>
  
  <p>They didn't work for me either.</p>
  
  <p>Does someone know why I cannot create a table?</p>
  
  <p>Any help is appreciated.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>According to @Genuine 's answer, it actually works in <code>mysql</code> but I cannot manage to run the query through <code>bash</code>. Here is what <code>mysql</code> looks like from the terminal:</p>
  
  <p><a href="https://i.stack.imgur.com/Qd662.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qd662.png" alt="enter image description here"></a></p>
  
  <p>I've done lots of reading about how to connect the <code>bash</code> script to the according database, and I reiterate that this should work:</p>
  
  <p><code>mysql -u root -e "USE test; CREATE TABLE information (...);"</code></p>
  
  <p>But it doesn't and still shoots the <code>ERROR 1046 (3D000)</code>.</p>
  
  <p>Is something wrong my <code>bash</code> syntax?</p>
  
  <p>It's also worth mentioning that @Genuine pointed out the correct syntax:</p>
  
  <p><code>USE test; SELECT DATABASE();</code></p>
  
  <p>Which now displays:</p>
  
  <pre><code>+------------+
  | DATABASE() |
  +------------+
  | test       |
  +------------+
  </code></pre>
  
  <hr>
  
  <p><strong>Note</strong>: The above script snippets are written sequentially, meaning that I first <code>CREATE DATABASE test;</code>, then <code>USE test;</code> and lastly <code>CREATE TABLE information (...);</code>. My latest connection is through <code>root@127.0.0.1</code> and I essentially utilise <strong>Sequel Pro</strong> to help me test my queries first.</p>