【网络安全实验】解决 ERROR 1064 (42000): You have an error in your SQL syntax ... near …

背景

今天做网络安全的时候,遇到了这个错误,这个问题之前遇到过几次,但是总是会因为疏忽又相遇,今天把这个问题写出来,加深印象吧。

任务

操作4:联合查询猜字段数

联合查询字段数量不同:select user,password from users union select
user,password  from mysql.user;
猜前面的查询字段数
select user,first_name,password from users union select 1;
select user,first_name,password from users union select 1,2;
....

报错如下:

select user,password from users union select user,password  from mysql.user;
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 ':select user,first_name,password from users union select user,password  from ' at line 1

解决

其实这个问题就是语法上的错误,在MySQL中,为了区分MySQL的关键字与普通字符,MySQL引入了一个反引号。

详情见:传送门

反引号不知道在哪?(快看下面这张图吧…)

select `user`,`password` from users union select `user`,`password`  from mysql.user;

再次运行就不会报错了

学如逆水行舟,不进则退

猜你喜欢

转载自blog.csdn.net/weixin_42429718/article/details/106690378