等同团队 Linux head 和 tail 在 MySQL

在 Linux 很容易从上面或从下面那里获得前几个数据

head



tail

团队。

wolf@linux:~$ cat db.txt 
| information_schema |
| database_name |
| mysql |
| opencart |
| wordpress |
| performance_schema |
| sys |
wolf@linux:~$

最佳 2

wolf@linux:~$ cat db.txt | head -2
| information_schema |
| database_name |
wolf@linux:~$

最后的 2

wolf@linux:~$ cat db.txt | tail -2
| performance_schema |
| sys |
wolf@linux:~$

是否有类似的团队 MySQL?

所有数据库

mysql> SHOW DATABASES;
+--------------------+
| Databases |
+--------------------+
| information_schema |
| database_name |
| mysql |
| opencart |
| wordpress |
| performance_schema |
| sys |
+--------------------+

7 rows in set (0.00 sec)
mysql>

期望的结果: 2 最佳数据库

mysql> <mysql command="" here="">
+--------------------+
| Databases |
+--------------------+
| information_schema |
| database_name |

期望的结果:最后 2 数据库

mysql&gt; <mysql command="" here="">
| performance_schema |
| sys |
+--------------------+

</mysql></mysql>
已邀请:

涵秋

赞同来自:

在 MySQL 没有人想要的球队

head

或者

tail

.

最简单的方法 - 使用shell中运行mysql请求

mysql -e

然后传递结果

head

或者

tail

, 例如

$ sudo mysql -e "SHOW DATABASES" --defaults-file=/etc/mysql/debian.cnf | tail -2
performance_schema
sys

如果你想从shell做到这一点 mysql, 您需要请求

information_schema

数据库这样的数据库:

mysql> (SELECT `SCHEMA_NAME` FROM `information_schema`.`SCHEMATA` 
ORDER BY `SCHEMA_NAME` DESC LIMIT 2) ORDER BY `SCHEMA_NAME`;
+--------------------+
| SCHEMA_NAME |
+--------------------+
| performance_schema |
| sys |
+--------------------+
2 rows in set (0,00 sec)

你在哪里使用

LIMIT

限制所需行数的结果集。

要回复问题请先登录注册