View and specify existing databases
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bjpowernode |
| eladmin |
| mysql |
| performance_schema |
| sqlalchemy |
| sys |
| test |
+--------------------+
8 rows in set (0.04 sec)
Specify the current default database
mysql> use bjpowernode;
Database changed
mysql>
View currently used libraries
mysql> select database();
+-------------+
| database() |
+-------------+
| bjpowernode |
+-------------+
1 row in set (0.08 sec)
View tables in the current library
mysql> show tables;
+-----------------------+
| Tables_in_bjpowernode |
+-----------------------+
| DEPT |
| EMP |
| SALGRADE |
+-----------------------+
3 rows in set (0.08 sec)
View tables in other libraries
show tables from ;
For example, view the table in the test library
mysql> show tables from test;
+----------------+
| Tables_in_test |
+----------------+
| DEPT |
| EMP |
| SALGRADE |
| s1 |
| t1 |
| t2 |
| tx |
+----------------+
7 rows in set (0.05 sec)
View table structure
desc
<table name>;
mysql> desc EMP;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| EMPNO | int(4) | NO | PRI | NULL | |
| ENAME | varchar(10) | YES | | NULL | |
| JOB | varchar(9) | YES | | NULL | |
| MGR | int(4) | YES | | NULL | |
| HIREDATE | date | YES | | NULL | |
| SAL | double(7,2) | YES | | NULL | |
| COMM | double(7,2) | YES | | NULL | |
| DEPTNO | int(2) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
8 rows in set (0.08 sec)
View the creation statement of the table
show create table <table name>;
......
| EMP | CREATE TABLE `EMP` (
`EMPNO` int(4) NOT NULL,
`ENAME` varchar(10) COLLATE utf8_bin DEFAULT NULL,
`JOB` varchar(9) COLLATE utf8_bin DEFAULT NULL,
`MGR` int(4) DEFAULT NULL,
`HIREDATE` date DEFAULT NULL,
`SAL` double(7,2) DEFAULT NULL,
`COMM` double(7,2) DEFAULT NULL,
`DEPTNO` int(2) DEFAULT NULL,
PRIMARY KEY (`EMPNO`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
....