查看和指定现有的数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bjpowernode |
| eladmin |
| mysql |
| performance_schema |
| sqlalchemy |
| sys |
| test |
+--------------------+
8 rows in set (0.04 sec)
指定当前缺省数据库
mysql> use bjpowernode;
Database changed
mysql>
查看当前使用的库
mysql> select database();
+-------------+
| database() |
+-------------+
| bjpowernode |
+-------------+
1 row in set (0.08 sec)
查看当前库中的表
mysql> show tables;
+-----------------------+
| Tables_in_bjpowernode |
+-----------------------+
| DEPT |
| EMP |
| SALGRADE |
+-----------------------+
3 rows in set (0.08 sec)
查看其他库中的表
show tables from ;
如查看test库中的表
mysql> show tables from test;
+----------------+
| Tables_in_test |
+----------------+
| DEPT |
| EMP |
| SALGRADE |
| s1 |
| t1 |
| t2 |
| tx |
+----------------+
7 rows in set (0.05 sec)
查看表的结构
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)
查看表的创建语句
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 |
....