Thursday, September 28, 2017

Connect and Show Databases in MySQL / MariaDB

After launching the MySQL/MariaDB console, user are able to access to the content of the database. However, one MySQL/MariaDB can consists of more than one database. User can view the list of databases through the command below:
the result of the command are shown in Figure 1 below:
Figure 1
Notice that there are only 2 databases in the server? This result does not show the actual list of the result because the user have not login to the server. Therefore, the rest of the databases are hidden until user login. To login to the MySQL server, a user require a username and password. the default username for the MySQL / MariaDB in XAMPP are "root" and no password is set.

To login to the MySQL / MariaDB server with username can done by using the command below:
The command "-u" is follow by username, while "-p" indicates the use of password to login. Figure 2 below show the command in action with the default username and password for the MySQL / MariaDB in XAMPP.
Figure 2: Login command in action.

After login to the server with username and password, the same show databases command provide a different output. the new output are shown in Figure 3 below.
Figure 3 Console result to show databases after login.
Notice the extra databases in the list compare to the result in Figure 1 before login? This is the full list of databases that user "root" can view and access.