mysql - 如何在 MySQL 的命令行中显示变量的值?

标签 mysql variables command-line

我尝试了以下 -

我在命令提示符下创建了一个变量如下 -

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 的值呢?

最佳答案

只需 SELECT 像这样的变量:

SELECT @myId;

这是关于用户定义变量的 MySQL 文档:

http://dev.mysql.com/doc/refman/5.5/en/user-variables.html

关于mysql - 如何在 MySQL 的命令行中显示变量的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18838611/

相关文章:

java - 动态设置 JRadioButton 上的文本

python - 我可以将一个函数分配给一个变量以在另一个函数中使用吗?

windows - 批处理文件删除文件和文件夹

python - 如何将文件名作为参数传递到我的模块中?

mysql - HTTP 状态 500 - 处理 JSP 页面时发生异常,未检索到数据

javascript - 如何循环存储并计算 sencha 上的字段数据

mysql - 根据字段值更改mysql表连接

variables - perl6 无法初始化状态变量。需要帮助

swift - 在命令行工具中获取资源路径

mysql - 在 MySQL 中,为什么在使用未提交读时从 select 设置变量会获取锁?