MySQL8.0移除PASSWORD函数
使用SQLyog在进行表数据的插入时,
INSERT INTO `users`(`id`,`username`,`password`,`email`) VALUES (1,'admin',PASSWORD('123456'),'admin@gmail.com');
发现报错如下
1 queries executed, 0 success, 1 errors, 0 warnings 查询:INSERT INTO `users`(`id`,`username`,`password`,`email`) VALUES (1,'admin',PASSWORD('123456'),'admin@gmail.com') 错误代码: 1064 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 '('123456'),'admin@gmail.com')' at line 2
说是语法错误❌,检查发现是我是的MySQL是8.0.27
,查看MySQL 8.0 Reference Manual
已经移除了PASSWORD加密函数,因此8.0以后版本的加密压缩函数只能采用以下函数
- MD5()
- SHA1()
- SHA()
完整的加密/压缩函数如下表:
参考MySQL 8.0 Reference Manual
https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_password
解决办法
INSERT INTO `users`(`id`,`username`,`password`,`email`) VALUES (1,'admin1',MD5('123456'),'admin1@gmail.com'), (2,'admin2',SHA('123456'),'admin2@gmail.com'), (3,'admin3',SHA1('123456'),'admin3@gmail.com'), (4,'admin4',SHA1('123456'),'admin4@gmail.com');
可以看到插入数据成功了
END