某些 mySQL 语句仅在附加 \g 后才起作用,其他语句不介意? [英] Some mySQL statements only work after appending \g, other statements don't mind?

查看:51
本文介绍了某些 mySQL 语句仅在附加 \g 后才起作用,其他语句不介意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在不使用 phpMyAdmin 的情况下以原始形式接受 mySQL 命令,但到目前为止我遇到了这个小问题......

I'm trying to embrace mySQL commands in the raw form without using phpMyAdmin and I ran into this little issue so far...

我只是想知道,我可以使用 wamp 服务器连接到我的数据库,但如果不输入 \g,某些命令将无法运行.例如,我可以连接,输入密码,然后立即尝试通过以下方式创建数据库:

I'm just wondering, I can connect to my db using wamp server and some commands won't work without typing \g after. For instance, I can connect, type my password and then immediately if I just try to create a database via:

CREATE DATABASE testing

它把我推到一个看起来像这样的换行符:

It pushes me into a newline that looks like so:

mysql> CREATE DATABASE testing
    ->

1.发生这种情况后,我如何回到常规行进行输入?我一直不得不关闭命令提示符并重新启动,这很麻烦.2. 为什么要这样做?然后当我输入以下命令时,该命令工作正常.

1. How do I get back to a regular line to type after this happens? I keep having to close the command prompt and re initiate which is a hassle. 2. Why does it do this? Then when I type the following the command works just fine.

CREATE DATABASE testing \g

好的,现在如果是这样的话,我会理解并且总是在所有事情之后输入 \g 因为我知道编程中的一些事情只是是".但是,我可以在没有 \g 的情况下输入这一行,它可以很好地更改数据库.

OK, now if that were the case I'd just understand and always type \g after everything because I know some things just "ARE" in programming. But then, I can type this line without the \g and it changes databases just fine.

USE firstdb

我还没有进一步测试哪些命令可以使用/不使用 GO 命令,但我想我会在让自己困惑一百万次之前问一下.

I haven't tested further on which commands do and don't work with/without the GO command but I thought I'd ask before I confuse myself a million times.

非常感谢 SO 社区!提前谢谢.

Much appreciated SO community! Thx in advance.

(另外,由于我是新手,所以有人可以就如何创建这些代码片段发表评论,但采用内联块格式,因此我不必总是将我的代码引用分解为换行?谢谢!)

(Also, since I'm new to SO can someone please leave a comment on how to create those code snippets, but in the inline-block format so I don't have to always have to break my code references out onto new lines? Thanks!)

推荐答案

分号 ; 是 SQL 中的标准语句分隔符.在 MySQL 的情况下,服务器不需要看到它,所以命令行客户端实际上并没有发送它......但它会等待它,直到一个分隔符后跟一个换行符之前,什么都不会发送到服务器遇到了.

The semicolon ; is the standard statement delimiter in SQL. In the case of MySQL, the server doesn't need to see it, so the command line client doesn't actually send it... but it waits for it, and nothing is sent to the server until a delimiter followed by a newline is encountered.

异常是不会发送到服务器或不会作为 SQL 发送的内容.(除了 USE 语句之外,还有另一种方法来更改当前数据库,使用特制的数据包,并且 afaik MySQL cli 仍然使用该方法,我猜想,为什么 USE>USE 是一个奇怪的例外.)

Exceptions are things that don't get sent to the server, or don't get sent as SQL. (There's another way, other than the USE statement, to change the current database, using a specially-crafted packet, and afaik the MySQL cli still uses that method, which is, I assume, why USE is a strange exception.)

您可以将分隔符更改为其他内容.通常,您会看到类似这样的内容

You can change the delimiter to something else. Commonly, you'll see something like this

mysql>  DELIMITER $$

这允许您将 SQL 发送到包含 ; 整体的服务器,而客户端在看到看起来像分隔符的内容时不会认为您已经完成.这用于声明过程、函数、触发器和事件.在语句或语句组的末尾,每个语句都以 $$ 结尾,您将其重新设置.

This allows you to send SQL to the server that contains a ; en bloc, without the client thinking you were done when it saw what looks like a delimiter. This is used for declaring procedures, functions, triggers, and events. At the end of the statement, or group of statements, each terminated with $$, you set it back.

mysql> DELIMITER ;

注意 ; 之前有一个空格.

Note there's a space before the ;.

这篇关于某些 mySQL 语句仅在附加 \g 后才起作用,其他语句不介意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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