Simple Basic MySql – beginning mysql db management

Problem

You want to know how to do the following, through mysql command line interface:

    Connect to the mysql daemon
    Show the databases your user has access
    Show tables defined under that db
    Show schema for given table


Solution



Example


mysql -u'username' -p'password' -h'mysql_host'

mysql_host is optional if the daemon is running on the same host.

Show databases

show databases;

Show tables

show tables;

Describe tables

use demo;describe demo;

For example:

mysql> show databases;+----------+| Database |+----------+| demo     || test     |+----------+2 rows in set (0.00 sec)mysql> use demo;Database changedmysql> show tables;+----------------+| Tables_in_demo |+----------------+| demo_table     |+----------------+1 row in set (0.00 sec)mysql> desc demo_table;+-------+--------------+------+-----+---------+-------+| Field | Type         | Null | Key | Default | Extra |+-------+--------------+------+-----+---------+-------+| id    | mediumint(9) |      | PRI | 0       |       || day   | varchar(20)  |      |     |         |       || val   | tinyint(4)   |      |     | 0       |       |+-------+--------------+------+-----+---------+-------+3 rows in set (0.10 sec)


Reference



Leave a Reply

Your email address will not be published. Required fields are marked *