我可以为 MySQL 客户端中的所有选择设置默认 LIMIT 吗? [英] Can I set a default LIMIT for all selects in the MySQL client?

查看:62
本文介绍了我可以为 MySQL 客户端中的所有选择设置默认 LIMIT 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 MySQL 客户端(命令行)中进行查询.

I am making queries in the MySQL client (command line).

有没有办法为 SELECT 查询设置默认限制?每次都打字很烦人,如果我忘记了,有时我会得到数千个我不想要的结果.

Is there a way to set a default LIMIT for SELECT queries? It's tiresome to type each time, and if I forget it, I sometimes end up with thousands of results that I didn't want.

推荐答案

是的.设置 select-limit 变量,或者通过在命令行上传递它:

Yes. Set the select-limit variable, either by passing it on the command line:

mysql --select-limit=1000

或者在~/.my.cnf中设置:

[client]
select-limit = 1000

您还可以通过将 safe-updates 选项设置为 1 来设置 select-limit,这也会阻止您运行 UPDATEDELETE 不涉及键约束的查询.(这是防止某些常见的危险错误的有用方法.)

You can also set select-limit by setting the safe-updates option to 1, which will also prevent you from running UPDATE or DELETE queries which do not involve a key constraint. (This is a useful way of preventing certain common, dangerous mistakes.)

这篇关于我可以为 MySQL 客户端中的所有选择设置默认 LIMIT 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆