当我使用值作为变量从 shell 脚本执行 MySQL 查询时,它显示
ERROR 1064 (42000) at line 1: 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 '@gmail.com' at line 1
我的代码
#!/bin/bash
email='new_user@gmail.com'
# Checking - is the email already exists,
email_exists=$(mysql -u username -ppassword -e "SELECT id FROM db.user where email=$email;")
使用内联(不使用变量)时没问题。
仅供参考:我使用电子邮件作为变量,因为我需要在代码中的某个地方重用。