我试过以下几种方法-
我在命令提示符下创建了一个变量,如下所示-
mysql> set @myId = 1;
Query OK, 0 rows affected (0.00 sec)然后,为了显示它,我尝试了以下命令,但没有成功-
mysql> show myId;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'myId' at line 1
mysql> show @myId;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '@myId' at line 1
mysql> PRINT @myId;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'PRINT @myId' at line 1
mysql> PRINT myId;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'PRINT myId' at line 1那么如何显示@myId的值呢?
发布于 2013-09-17 06:53:48
只需像这样简单地SELECT变量:
SELECT @myId;以下是有关用户定义变量的MySQL文档:
发布于 2018-10-17 21:33:21
如果你正在寻找一个像OP一样自己设置的变量,那么@MikeBrant的答案是正确的:
SELECT @myId;但是,如果您想要查看MySQL系统变量(这正是我在这里寻找的),那么您需要运行:
show variables like '%slow%';或者有可能:
show global variables like '%slow%';发布于 2018-10-19 02:27:25
显示全局状态,如'%com_stmt%';可用于使用通配符确定任何显示全局状态的当前值。
同样,SELECT @@thread_cache_size;可用于显示任何特定的SHOW GLOBAL VARIABLES current value。
有超过300个全局状态值。
有400多个带或不带值的全局变量。(可以是空占位符)。
您不能在MySQL中创建全局变量。
https://stackoverflow.com/questions/18838611
复制相似问题