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

我尝试了以下 -

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

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

https://stackoverflow.com/questions/18838611/

相关文章:

mysql - ON UPDATE RESTRICT 有什么作用?

mysql - 错误 2002 (HY000) : Can't connect to local M

php - 如何使用 laravel 连接 mysql?

php - Laravel OrderBy 关系计数

php - MySQL 查询随机滞后

mysql - 如何同步开发和生产数据库

php - Doctrine2 迁移向下迁移并从浏览器而不是命令行迁移

mysql - 在 Postgresql 中模拟 MySQL 的 ORDER BY FIELD()

php - 一次查询 MySQL 插入多行

php - 将大量点击记录到 MySQL 数据库中的最佳实践