MySQL command to show list of databases on server

by Vivek Gite · 12 comments

Q. I am new to MySQL database server. How do I show the list of databases on my server? Is there any good GUI frontend exists for the same?

A. You can use 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
Output:

mysql>

You may need to provide mysql username, password and hostname, use:
$ mysql --user=your-user-name --password=your-password
mysql>

To list database type the following command

mysql> show databases;
Output:

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

information_schema and mysql are name of databases. To use these database and to list available tables type the following two commands:
mysql> use mysql;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:
mysql> show tables;Output:

+---------------------------+
| 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)

mysql>

GUI tools

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

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 12 comments… read them below or add one }

1 sumudu sanjeewa 03.05.08 at 9:44 am

gud site for learn

2 Dog 03.25.08 at 3:23 am

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

3 Michael Sharman 08.22.08 at 5:47 am

Nice tips, very helpful.

Thanks

4 lady 02.13.09 at 1:38 am

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?

5 Lepe 03.03.09 at 4:47 am

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

6 video x ware 03.07.09 at 4:49 am

Very helpful tips, thanks

7 video x ware 03.07.09 at 4:54 am

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

8 Santanu 06.04.09 at 7:20 am

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.

9 joy 10.02.09 at 12:21 pm

How to setup a working database named ‘RCC’ in a new server. Please send me ur commands

10 Zaid 11.19.09 at 2:10 pm

thank you so much really beneficial.

11 Raja 12.04.09 at 10:23 am

Its nice to learn

12 jeevan 02.25.10 at 6:55 am

At present i am working in one database . i want to know current working database name.give command plz.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All