Database Reference
In-Depth Information
All of the options in the previous example are in brackets ( [] ) to show that they are all
optional. The parts in angle brackets ( <> ) are bits that we must supply if we choose to
use that option. For example, if we use the -u option, we must supply a username.
Most of the time, we will use the user ( -u ) and password ( -p ) options. We will also
often specify the database that we want to connect to when the client launches. When
we connect remotely to a MariaDB server on another computer, we will use the host
( -h ) option.
A successful connection will look similar to the following:
daniel@gandalf ~ $ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 5.5.30-MariaDB-mariadb1~quantal-log mariadb.org binary
distribution
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.
MariaDB [(none)]>
The last line of the output, MariaDB [(none)]> , is the MariaDB prompt. It appears
whenever MariaDB is waiting for us to give it a command. Apart from its primary
purpose, the prompt gives us two pieces of very useful information. First, the
prompt says MariaDB which tells us that we are connecting to an actual MariaDB
database server (as opposed to a compatible database server that isn't actually
MariaDB). Second, the part in brackets tells us which database on the server we are
currently using; in this case, we aren't using any database, so it says (none) .
Using a database
We generally want to be connected to a specific database when we use the command-
line client. To use a database, we either specify it on the command-line when
launching the client as shown in the previous section, or we use the USE command,
to tell the client which database we want to talk to. The following example illustrates
connecting to a database named test . Notice that the prompt changes to let us know
the name of the database it is currently connected to.
MariaDB [(none)]> USE test;
Database changed
MariaDB [test]>
 
Search WWH ::




Custom Search