How to Show MySql Database and Table List in Linux

 

Hello devs,

in this linux mysql command line show databases tutorial, i will show you how to show all database from your server and also how to show table list from database in linux. To show database, we have to first login our mysql server.

Sometimes such situation arrives that we have to check database and table list using command line in linux server. So to check that jsut follow the below command:

mysql command line get list of databases:

First of all, we have to access our mysql server. To access mysql server, run below command:

mysql -u user_name -p

 

We will get output like:

output
 ❯ mysql -u mahedi -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.3.34-MariaDB-0+deb10u1 Debian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

 

Now to show all the databases, run the below command:

show databases;

 

You will get the output like:

output
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| 10minutedb         |
| forum              |
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
| task               |
| test               |
| wordpress          |
| zcart              |
+--------------------+
10 rows in set (0.005 sec)

MariaDB [(none)]> 

 

Now we need to check all the tables for a specific database. So run below command:

use database_name;

 

Then we will see the output like:

output
MariaDB [(none)]> use forum
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [forum]> 

 

Now we need to show all the tables of the forum database. So run the below command:

show tables;

 

Then we will get all the table lists like:

output
MariaDB [forum]> show tables;
+------------------------+
| Tables_in_forum        |
+------------------------+
| categories             |
| failed_jobs            |
| likes                  |
| migrations             |
| password_resets        |
| personal_access_tokens |
| questions              |
| replies                |
| users                  |
+------------------------+
9 rows in set (0.001 sec)

MariaDB [forum]>

 

Now if you want to check all number of rows of a table then run

select count(*) from likes;

 

Then we will see the number of row like: 

output
MariaDB [forum]> select count(*) from likes;
+----------+
| count(*) |
+----------+
|       15 |
+----------+
1 row in set (0.000 sec)

MariaDB [forum]> 

 

Read also: How to Export MySQL Database Using SSH

 

Hope it can help you.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js
ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT