请问为什么我执行以下语句会报错?

err := a.MysqlDB.db.Exec("CREATE USER ? IDENTIFIED BY ?", a.Name, a.Pwd).Error 报错信息为 [1.918ms] [rows:0] CREATE USER 'Reiis' IDENTIFIED BY '12345' 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 '? IDENTIFIED BY ?' at line 1

而我不管是拼接字符串还是直接在mysql中执行上述sql语句,都是能成功运行的。 以下代码可以成功运行: cmd := fmt.Sprintf("CREATE USER '%s' IDENTIFIED BY '%s'", a.Name, a.Pwd) err := a.MysqlDB.db.Exec(cmd).Error

请问什么原因呢?谢谢🙏

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: ivila

@John-0xFFFFFF it's not a gorm problem, it's a mysql problem.

you can check this link to see why you cannot using a prepared statement with placeholder to do this: https://stackoverflow.com/questions/67047078/create-user-and-create-role-as-preparedstatement-with-placeholder

and you can check this link to see how you can achieve your goal by work around: https://stackoverflow.com/questions/35749340/create-user-fails-with-mysqli-prepared-statements, but as what it says: with users created dynamically you are doing something wrong

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: ivila

@jinzhu maybe just close this issue as it's not a gorm problem(what I mentioned above).

Comment From: a631807682

@ivila Thank you for your contribution