MySQL: first commands into the shell

MySQL has its own shell. We can enter using the following command:

mysql -h servername -u username -p

Where “servername” can be omitted if we installed MySQL in our computer. The prompt switches from “$” to “mysql>” and we can type SQL commands.

We want to:

  • list the databases
  • select a particular database
  • list the tables in that database
  • list the fields of a table

First we want to see which database are present. If we have the privileges of course we can create a new one. The “show databases” command list the databases present in the server.

Show db

To start “working” with a database (sort of “cd”) we can use the use databasename statement.

When inside a database we can list the tables contained with “show tables“:

To list the fields of a table (that is understanding its structure) can be done with the “describe tablename” command.

A final remark: MySQL commands are case-insensitive, but database/table/fields names are case-sensitive!

Tagged

Leave a Reply

Your email address will not be published.