Operation syntax under mysql_ command line

Operation syntax under mysql_ command line

Variable use

-- 定义变量
SET @a = 1;
-- 查看变量
SELECT @a;
-- 同一个变量可以存储不同类型的值
set @a '你好';
-- 变量间赋值
set @b=@a;
-- 查询结果赋值【这个查询结果必须只有一个值】
set @a = (select m1 from t1 limit 1);
SELECT n1 FROM t1 LIMIT 1 INTO @b;
-- 多个变量同时赋值
SELECT m1, n1 FROM t1 LIMIT 1 INTO @a, @b;
-- 将变量传递给存储过程
call p1(@a);

Send multiple commands at the same time

At MySQLthe interactive interface of the client, when we complete the keyboard input and press 回车键, the MySQLclient will detect whether the content we input contains ;, \gor one of \Gthese three symbols, and if so, it will send the content we input to server. In this way, if we want to send compound statements (that is, statements composed of one or more statements) to the server, we need to write these statements on one line. Like the following:

mysql> SELECT * FROM t1 LIMIT 1;SELECT * FROM t2 LIMIT 1;SELECT * FROM t3 LIMIT 1;

You can use delimitercommands to customize MySQLthe symbol that detects the end of input:

-- 将$符号作为命令发送的提示符(以前是回车)
mysql> delimiter $ 
mysql> SELECT * FROM t1 LIMIT 1;
    -> SELECT * FROM t2 LIMIT 1;
    -> SELECT * FROM t3 LIMIT 1;
    -> $

references

https://mp.weixin.qq.com/s?__biz=MzIxNTQ3NDMzMw==&mid=2247483963&idx=1&sn=eaf578dcb032daf0409179d95439e3b5&scene=19#wechat_redirect stored procedure (1) Introduction to custom variables

Guess you like

Origin blog.csdn.net/u013617791/article/details/104847966