MySQL 命令行客户端尝试查看 table 时出现 1064 错误,但在 MySQL Workbench 中工作正常
1064 error in MySQL Command line client when trying to view table but works fine in MySQL Workbench
所以我在 MySQL Workbench 中创建了一个数据库,我试图在 MySQL 命令行客户端上查看它们,因为我想在那里进行查询而不是 workbench.
情况如下:
mysql> use policestation(crime);
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_policestation(crime) |
+--------------------------------+
| accused |
| case |
| complainant |
| investigation_officer |
| outcome |
| section_of_law |
+--------------------------------+
6 rows in set (0.04 sec)
mysql> select * from case;
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 'case' at line 1
相同的查询在 MySQL Workbech 中运行良好。它也适用于命令行客户端中的所有其他表。
它的 b/c 大小写是 MySQL 保留关键字:https://dev.mysql.com/doc/refman/5.5/en/keywords.html
您需要用刻度线而不是引号将保留关键字括起来。
示例:
SELECT * FROM `case`
与
不一样
SELECT * FROM 'case'
这里还有另一个有用的 link:
Syntax error due to using a reserved word as a table or column name in MySQL
所以我在 MySQL Workbench 中创建了一个数据库,我试图在 MySQL 命令行客户端上查看它们,因为我想在那里进行查询而不是 workbench.
情况如下:
mysql> use policestation(crime);
Database changed
mysql> show tables;
+--------------------------------+
| Tables_in_policestation(crime) |
+--------------------------------+
| accused |
| case |
| complainant |
| investigation_officer |
| outcome |
| section_of_law |
+--------------------------------+
6 rows in set (0.04 sec)
mysql> select * from case;
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 'case' at line 1
相同的查询在 MySQL Workbech 中运行良好。它也适用于命令行客户端中的所有其他表。
它的 b/c 大小写是 MySQL 保留关键字:https://dev.mysql.com/doc/refman/5.5/en/keywords.html
您需要用刻度线而不是引号将保留关键字括起来。 示例:
SELECT * FROM `case`
与
不一样SELECT * FROM 'case'
这里还有另一个有用的 link: Syntax error due to using a reserved word as a table or column name in MySQL