Connecting to MariaDB

To start the client and connect to MariaDB, we open up a command-line or terminal window and type mysql with some options and press Enter. The basic syntax is as follows:

mysql [-u <username>] [-p] [-h <host>] [<database>]

All the options in the previous syntax example are in square 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 username (-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.

Tip

It is possible to add the password after -p on the command line, with a couple of caveats. First, there can't be a space between the -p and the password. For example if our username is tom and our password is correcthorse we can use the following command line to log in to MariaDB:

mysql -u tom -pcorrecthorse

The second caveat is that doing this is very insecure and should not, in fact, be done. Command-line interpreters and shells are almost always configured to save the commands we run in a history file that could have insecure permissions, meaning that if we make a habit of typing out our password on the command line like this, an attacker only has to gain access to the history file to find out our MariaDB user password.

A successful connection will look similar to the following:

daniel@pippin:~$ mysql -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g. 
Your MariaDB connection id is 209 
Server version: 10.1.2-MariaDB-1~trusty-wsrep-log mariadb.org binary distribution, wsrep_25.10.r4123 

Copyright (c) 2000, 2014, Oracle, SkySQL 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 the brackets tells us which database on the server we are currently using by default; in this case, we aren't using any database, so it says (none).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.225