MySQL command to show list of databases on server

last updated in Categories , , , , , , ,

I am a new Linux user and never used MySQL database server before. How do I show the list of databases on my server? Is there any good GUI frontend exists for the same purpose?

You can use the mysql command to connect to mysql server and list available databases.


Task: Mysql list databases

mysql is a simple command-line tool. mysql is command line and it is very easy to use. Invoke it from the prompt of your command interpreter as follows:
$ mysql
Sample outputs:


You may need to provide mysql username, password and hostname, use:
$ mysql --user=your-user-name --password=your-password
$ mysql -u your-user-name -p'Your-password' -h your-hostname

To list database type the following command at mysql prompot:

mysql> show databases;

| Database           |
| information_schema |
| mysql              |
2 rows in set (0.00 sec)

In this sample output information_schema and mysql are name of databases. To use database and to list available tables type the following two commands:
mysql> use mysql;
Sample output:

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

Now list tables, run:
mysql> show tables;
Sample outputs:

| Tables_in_mysql           |
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
17 rows in set (0.00 sec)


Shell one liner

Use the following one liner to get the same information:

mysql -u root -p -e 'show databases;'

GUI tools

Since you are new to MySQL, it is better to use GUI tools. Please refer the previous article about “GUI Tools for managing MySQL databases server“.


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

51 comment

  1. you can use the -e option to execute some queries on the command line, EG, to list databases:
    mysql -e “show databases” -u -p

  2. how can i know if there is a database server on my pc?
    i tried this command:
    -e “show databases” -u -p
    and i got this error:
    ERROR 2006 (HYOOO):MySQL server has gone away
    No connection. Trying to reconnect. . .
    Connection id: 19
    Current database: TCPDUMP

    ERROR 1064 (42000): You have and error in your SQL syntax;check the manual to your corresponds to your MySQL server version for the right syntax to use near ‘-e “show databases” -u -p’ at line 1

    can anyone help me?

    1. In this above error indicates Mysql error ,u can check to identify correcly connections are established or not,and once u check your transcational data.

  3. Hi lady,

    I suppose you are using …. Linux? or Windows? if you are using Windows, just go to your control panel and check in “Add/Remove Programs” if you see something like “mysql”. Also you can check in services under Administrative tools.
    Now, if you are in Linux,
    type “mysql” and then press “TAB” twice and you will see a list of commands like:

    mysql mysqlimport
    mysqlaccess mysql_install_db
    mysqladmin mysqlmanager

    then mysql is installed. To know if it is running:

    nmap localhost

    and you will see a “3306/tcp open mysql”.

    Also, if you copy+paste some codes or example from web pages remember that sometimes the quotation mark is changed (looks similar but they are not)

    I hope this is helpful

  4. Another question, man.
    How can I delete a database or table under a database such as TEST?

  5. i m new to mysql and when i m trying to mysqlcheck -u root –analyze mysql then i m getting error ERROR 1064(42000). is there anybody who will help me to solve this problem? Please help me at the earliest.

  6. i am new in mysql. i tried to connection to mysql through php. i think problem in mysql server.
    i am use window base, xampp server for this. how to find out my server name, database name,username and password. when u use with servername with localhost they are not running
    successfully. i tried for this. i doing this activity last 2 days. but i am fail in this. so u advice me
    for above. i want to connect mysql to php. if u can example then best.

  7. This error comes when you write
    # mysql
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

    plz help

  8. Hello

    When you do the command SHOW DATABASE, i would like to know which condition is used for the sort of the output of this command ?

  9. Loading your data from a file. ( for windows )

    mysql> source ‘enter file name with including path’ ;

    eg: mysql> source d:/world.sql ; ( use forwards slash )

  10. i’m try to put mysql syntax but it is still error 1064 i dont know why?
    Is write a message You have ana error in your sql syntax; check the manual corresponds to your Mysql server version for the right syntax to use near ‘database’ line 1

  11. The results which I am getting after executing a query are too messed-up. How do I outline it in a readable or may be in a clear view, I mean in a table format?

  12. mysql> use mysql;
    ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘mysql’
    mysql> mysql –user=mlpc4 –password=mlpc4
    -> i got this error smbdy plz hlp me..

  13. why test database is there in mysql eventhough it is empty and at the mysql_secure_installation we can remove it.. then what is the use of this..??

  14. While migrating a database from an old server (Ubuntu 10.04) to a new one (14.04) I am getting this error: ERROR 2006 (HY000) at line 2692: MySQL server has gone away

    All the other databases worked except for this one. It will run for about 10 minutes then fail. Here is the command I used: mysql -u root -p cascade_test < /var/cascade_test.sql –max_allowed_packet=1060M

    The mysql dump I am using is in /var.

    Any help would be really appreciated.

  15. Fixed! It wasn’t working and I was using PuTTY. I tried it on my mac through terminal and it worked! Strange…

  16. Sorry to be negative, your end comment:

    “Since you are new to MySQL, it is better to use GUI tools”

    I have to disagree with, it is far better and quicker to learn to use the shell commands to do server admin, especially if doing many actions, like creating many databases or importing large amounts of data.

    But phpmyadmin is a great tool if you are working in the gui enviroment and want to make an adjustment for one off changes.I have not tried your other suggestion, but will now

    And as a positive I would like to say a big thanks to all the help I have got from your pages. On a search to resolve a problem I will always click the cyberciti link first.

    Thanks again

  17. 1. Consider the following relations of medical consultation centre:
    FACULTY (F_id, F-name, F-designation).
    PATIENT (P_id, P_name, p_address, date_of_ registration).
    CONSULTATION DATE (C_date, F_id, P_id).
    Create tables for above relations considering suitable data types and constraints. Insert 5
    appropriate tuples in the tables.
    Write the SQL statements for the following queries.
    1. Generate list of patients and their consultation detail.
    2. Find patients consulted by specific faculty.
    3. Find the details of the entire faculty whose designation is a senior doctor and have
    consultation date next month.
    4. Find the patient whose consultation date is today along with the concerned faculty

  18. Thanks for this article! Expand on it if you can and show us even more commands for us to experiment with.

    Still, have a question? Get help on our forum!