注释:
以/**注释内容**/
mysql> /**列出所有的数据库**/ show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_springcloud |
| mysql |
| performance_schema |
| test |
| wordpress |
| xinyu |
| xinyu2 |
| zabbix |
+--------------------+
9 rows in set (0.00 sec)
###注释是从‘#’字符到行尾
mysql> #这里是注释,到行尾都是注释,所以后面的命令不执行 showdatabases;
mysql>
如果遇到很长的sql语句的话,在控制台为了阅读方便,我们可以使用\,使之继续输入;
mysql> show \
-> databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db_springcloud |
| mysql |
| performance_schema |
| test |
| wordpress |
| xinyu |
| xinyu2 |
| zabbix |
+--------------------+
9 rows in set (0.00 sec)
mysql>
也支持正则like查询
mysql> show databases like '%inyu%';
+-------------------+
| Database (%inyu%) |
+-------------------+
| xinyu |
| xinyu2 |
+-------------------+
2 rows in set (0.00 sec)
同理,show tables也支持,用from语法,可以少一步use 数据库
mysql> show tables from test;
+----------------+
| Tables_in_test |
+----------------+
| hbk |
+----------------+
1 row in set (0.00 sec)
mysql> show tables from test like '%b%';
+----------------------+
| Tables_in_test (%b%) |
+----------------------+
| hbk |
+----------------------+
1 row in set (0.00 sec)
查看表定义,可以使用show create table 表名 \G
\G只是显示的格式更好看而已,也可以使用describe语法
mysql> use test;
mysql> show create table hbk \G;
*************************** 1. row ***************************
Table: hbk
Create Table: CREATE TABLE `hbk` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
ERROR:
No query specified
mysql> describe hbk;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> desc hbk;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
+-------+-------------+------+-----+---------+----------------+
2 rows in set (0.01 sec)
知识点注意:
数据名的最大长度64字节
表名的最大长度64字节
列名的最大长度64字节
索引名的最大长度64字节
别名的最大长度255字节
</div>