Select 带有二进制字段的语句
Select statement with Binary field
我试图通过识别存储为 SMALLINT 的 userID 和存储为 BINARY(32) 的 passwordTest 来 select 来自 table 的所有数据。这是我用来制作 table 的查询:
{ {CREATE TABLE IF NOT EXISTS `test`.`User`
(`UserID` SMALLINT UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(35) NOT NULL,
`lastname` VARCHAR(35) NOT NULL,
`passwordTest` BINARY(32) NOT NULL,
`registration_date` DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`UserID`),
UNIQUE INDEX `password_UNIQUE` (`passwordTest` ASC));}
这是我用来将测试值插入 table 的查询:
{INSERT INTO USER (firstname, lastname, passwordTest)
VALUES('Test','1','password');}
我的 SQL 查询无效:
{USE test;
SELECT * FROM USER WHERE userID = '00001' AND passwordTest = 'password';}
如有任何帮助,我们将不胜感激
因为您将密码列定义为二进制,所以您必须在where 子句中将密码转换为二进制。这适用于 mysql5.6
Select *
From User
Where UserID = '00001'
and passwordTest = cast('password' as BINARY(32))
我试图通过识别存储为 SMALLINT 的 userID 和存储为 BINARY(32) 的 passwordTest 来 select 来自 table 的所有数据。这是我用来制作 table 的查询:
{ {CREATE TABLE IF NOT EXISTS `test`.`User`
(`UserID` SMALLINT UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(35) NOT NULL,
`lastname` VARCHAR(35) NOT NULL,
`passwordTest` BINARY(32) NOT NULL,
`registration_date` DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`UserID`),
UNIQUE INDEX `password_UNIQUE` (`passwordTest` ASC));}
这是我用来将测试值插入 table 的查询:
{INSERT INTO USER (firstname, lastname, passwordTest)
VALUES('Test','1','password');}
我的 SQL 查询无效:
{USE test;
SELECT * FROM USER WHERE userID = '00001' AND passwordTest = 'password';}
如有任何帮助,我们将不胜感激
因为您将密码列定义为二进制,所以您必须在where 子句中将密码转换为二进制。这适用于 mysql5.6
Select *
From User
Where UserID = '00001'
and passwordTest = cast('password' as BINARY(32))